Merge pull request #3 from nventive/dev/jela/misc-adjust
Adjust visibility comparison with protected to internal modifiers
This commit is contained in:
Коммит
62af8d9f33
|
@ -44,5 +44,24 @@ namespace Uno.PackageDiff.Tests
|
|||
Assert.AreEqual(1, r.InvalidProperties.Length);
|
||||
Assert.AreEqual("MyProperty", r.InvalidProperties.First().Name);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void When_Target_Internal()
|
||||
{
|
||||
var context = _builder.BuildAssemblies();
|
||||
|
||||
var r = AssemblyComparer.CompareTypes(context.BaseAssembly, context.TargetAssembly);
|
||||
|
||||
Assert.AreEqual(0, r.InvalidTypes.Length);
|
||||
Assert.AreEqual(0, r.InvalidEvents.Length);
|
||||
Assert.AreEqual(0, r.InvalidFields.Length);
|
||||
Assert.AreEqual(3, r.InvalidMethods.Length);
|
||||
Assert.AreEqual(1, r.InvalidProperties.Length);
|
||||
|
||||
Assert.AreEqual("MyProperty", r.InvalidProperties.First().Name);
|
||||
Assert.AreEqual("System.Int32 Uno.PackageDiff.Tests.Sources.When_Target_Internal::get_MyProperty()", r.InvalidMethods.ElementAt(0).ToString());
|
||||
Assert.AreEqual("System.Void Uno.PackageDiff.Tests.Sources.When_Target_Internal::set_MyProperty(System.Int32)", r.InvalidMethods.ElementAt(1).ToString());
|
||||
Assert.AreEqual("System.Void Uno.PackageDiff.Tests.Sources.When_Target_Internal::MyMethod()", r.InvalidMethods.ElementAt(2).ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Uno.PackageDiff.Tests.Sources
|
||||
{
|
||||
public class When_Target_Internal
|
||||
{
|
||||
protected int MyProperty { get; set; }
|
||||
|
||||
protected void MyMethod() { }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Uno.PackageDiff.Tests.Sources
|
||||
{
|
||||
public class When_Target_Internal
|
||||
{
|
||||
internal int MyProperty { get; set; }
|
||||
|
||||
internal void MyMethod() { }
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Mono.Cecil;
|
||||
|
||||
namespace Uno.PackageDiff.Tests
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
@ -14,6 +14,8 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Sources\Given_AssemblyComparer_When_Target_Internal.base.cs" />
|
||||
<None Remove="Sources\Given_AssemblyComparer_When_Target_Internal.target.cs" />
|
||||
<None Remove="Sources\Given_ReportAnalyzer_When_Empty_IgnoreSet.base.cs" />
|
||||
<None Remove="Sources\Given_ReportAnalyzer_When_Empty_IgnoreSet.target.cs" />
|
||||
<None Remove="Sources\Given_ReportAnalyzer_When_IgnoreProperty.base.cs" />
|
||||
|
|
|
@ -68,13 +68,20 @@ namespace Uno.PackageDiff
|
|||
var q1 = from type in existingTypes
|
||||
from targetMethod in type.targetType.Methods
|
||||
let targetMethodParams = getMethodParamsSignature(targetMethod)
|
||||
where targetMethod.IsPublic
|
||||
where !type.sourceType.Methods.Any(m => m.Name == targetMethod.Name && targetMethodParams.SequenceEqual(getMethodParamsSignature(m)))
|
||||
where IsVisibleMethod(targetMethod)
|
||||
where !type.sourceType.Methods
|
||||
.Any(sourceMethod =>
|
||||
sourceMethod.Name == targetMethod.Name
|
||||
&& targetMethodParams.SequenceEqual(getMethodParamsSignature(sourceMethod))
|
||||
&& IsVisibleMethod(sourceMethod))
|
||||
select targetMethod;
|
||||
|
||||
return q1.ToArray();
|
||||
}
|
||||
|
||||
private static bool IsVisibleMethod(MethodDefinition targetMethod)
|
||||
=> targetMethod != null ? targetMethod.IsPublic || targetMethod.IsFamily : false;
|
||||
|
||||
private static string ExpandMethod(MethodDefinition method)
|
||||
{
|
||||
var parms = string.Join(", ", method.Parameters.Select(p => $"{p.ParameterType} {p.Name}"));
|
||||
|
@ -85,8 +92,12 @@ namespace Uno.PackageDiff
|
|||
{
|
||||
var q1 = from type in existingTypes
|
||||
from targetEvent in type.targetType.Events
|
||||
where targetEvent.AddMethod?.IsPublic ?? false
|
||||
where !type.sourceType.Events.Any(p => p.Name == targetEvent.Name && p.EventType.FullName != targetEvent.FullName)
|
||||
where IsVisibleMethod(targetEvent.AddMethod)
|
||||
where !type.sourceType.Events
|
||||
.Any(sourceEvent =>
|
||||
sourceEvent.Name == targetEvent.Name
|
||||
&& sourceEvent.EventType.FullName != targetEvent.FullName
|
||||
&& IsVisibleMethod(sourceEvent.AddMethod))
|
||||
select targetEvent;
|
||||
|
||||
return q1.ToArray();
|
||||
|
@ -96,7 +107,7 @@ namespace Uno.PackageDiff
|
|||
{
|
||||
var q1 = from type in existingTypes
|
||||
from targetField in type.targetType.Fields
|
||||
where targetField.IsPublic
|
||||
where targetField.IsPublic || targetField.IsFamily
|
||||
where !type.sourceType.Fields.Any(p => p.Name == targetField.Name && p.FieldType.FullName == targetField.FieldType.FullName)
|
||||
select targetField;
|
||||
|
||||
|
@ -107,8 +118,12 @@ namespace Uno.PackageDiff
|
|||
{
|
||||
var q1 = from type in existingTypes
|
||||
from targetProp in type.targetType.Properties
|
||||
where targetProp.GetMethod?.IsPublic ?? false
|
||||
where !type.sourceType.Properties.Any(p => p.Name == targetProp.Name && p.PropertyType.FullName == targetProp.PropertyType.FullName)
|
||||
where IsVisibleMethod(targetProp.GetMethod)
|
||||
where !type.sourceType.Properties
|
||||
.Any(sourceProperty =>
|
||||
sourceProperty.Name == targetProp.Name
|
||||
&& sourceProperty.PropertyType.FullName == targetProp.PropertyType.FullName
|
||||
&& IsVisibleMethod(sourceProperty.GetMethod))
|
||||
select targetProp;
|
||||
|
||||
return q1.ToArray();
|
||||
|
|
Загрузка…
Ссылка в новой задаче