This commit is contained in:
Eugene Sadovoi 2019-03-01 21:18:43 -05:00
Родитель c8a39a663f
Коммит 0a04222980
11 изменённых файлов: 45 добавлений и 101 удалений

Просмотреть файл

@ -10,7 +10,7 @@
</PropertyGroup>
<PropertyGroup>
<UnityAbstractionsVersion>4.0.*</UnityAbstractionsVersion>
<UnityAbstractionsVersion>4.1.*</UnityAbstractionsVersion>
</PropertyGroup>
</Project>

Просмотреть файл

@ -41,14 +41,19 @@ namespace Unity.Builder
// Process overrides if any
if (null != Overrides)
{
NamedType namedType = new NamedType
{
Type = type,
Name = name
};
// Check if this parameter is overridden
for (var index = Overrides.Length - 1; index >= 0; --index)
{
var resolverOverride = Overrides[index];
// If matches with current parameter
if (resolverOverride is IResolve resolverPolicy &&
resolverOverride is IEquatable<(Type, string)> comparer && comparer.Equals((type, name)))
resolverOverride is IEquatable<NamedType> comparer && comparer.Equals(namedType))
{
var context = this;

Просмотреть файл

@ -81,13 +81,9 @@ namespace Unity.Processors
protected override IEnumerable<ConstructorInfo> DeclaredMembers(Type type)
{
#if NETSTANDARD1_0
return type.GetTypeInfo()
.DeclaredConstructors
.Where(c => c.IsStatic == false && c.IsPublic);
#else
return type.GetConstructors(BindingFlags.Instance | BindingFlags.Public);
#endif
.Where(ctor => !ctor.IsFamily && !ctor.IsPrivate && !ctor.IsStatic);
}
#endregion

Просмотреть файл

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Unity.Builder;
@ -25,12 +24,18 @@ namespace Unity.Processors
protected override IEnumerable<FieldInfo> DeclaredMembers(Type type)
{
#if NETSTANDARD1_0
return GetFieldsHierarchical(type).Where(f => !f.IsInitOnly && !f.IsStatic);
#else
return type.GetFields(BindingFlags.Instance | BindingFlags.Public)
.Where(f => !f.IsInitOnly && !f.IsStatic);
#endif
var info = type.GetTypeInfo();
while (null != info)
{
foreach (var member in info.DeclaredFields)
{
if (!member.IsFamily && !member.IsPrivate &&
!member.IsInitOnly && !member.IsStatic)
yield return member;
}
info = info.BaseType?.GetTypeInfo();
}
}
protected override Type MemberType(FieldInfo info) => info.FieldType;
@ -68,28 +73,5 @@ namespace Unity.Processors
}
#endregion
#region Implementation
#if NETSTANDARD1_0
public static IEnumerable<FieldInfo> GetFieldsHierarchical(Type type)
{
if (type == null)
{
return Enumerable.Empty<FieldInfo>();
}
if (type == typeof(object))
{
return type.GetTypeInfo().DeclaredFields;
}
return type.GetTypeInfo()
.DeclaredFields
.Concat(GetFieldsHierarchical(type.GetTypeInfo().BaseType));
}
#endif
#endregion
}
}

Просмотреть файл

@ -27,28 +27,17 @@ namespace Unity.Processors
protected override IEnumerable<MethodInfo> DeclaredMembers(Type type)
{
#if NETSTANDARD1_0
return GetMethodsHierarchical(type)
.Where(c => c.IsStatic == false && c.IsPublic);
IEnumerable<MethodInfo> GetMethodsHierarchical(Type t)
var info = type.GetTypeInfo();
while (null != info)
{
if (t == null)
foreach (var member in info.DeclaredMethods)
{
return Enumerable.Empty<MethodInfo>();
if (!member.IsFamily && !member.IsPrivate && !member.IsStatic)
yield return member;
}
if (t == typeof(object))
{
return t.GetTypeInfo().DeclaredMethods.Where(m => !m.IsStatic);
}
return t.GetTypeInfo().DeclaredMethods.Where(m => !m.IsStatic)
.Concat(GetMethodsHierarchical(t.GetTypeInfo().BaseType));
info = info.BaseType?.GetTypeInfo();
}
#else
return type.GetMethods(BindingFlags.Instance | BindingFlags.Public);
#endif
}
#endregion

Просмотреть файл

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Unity.Builder;
@ -27,25 +26,23 @@ namespace Unity.Processors
protected override IEnumerable<PropertyInfo> DeclaredMembers(Type type)
{
#if NETSTANDARD1_0
return GetPropertiesHierarchical(type)
.Where(p =>
{
if (!p.CanWrite) return false;
var info = type.GetTypeInfo();
while (null != info)
{
foreach (var member in info.DeclaredProperties)
{
if (!member.CanWrite || 0 != member.GetIndexParameters().Length)
continue;
var propertyMethod = p.GetSetMethod(true) ??
p.GetGetMethod(true);
var setter = member.GetSetMethod(true);
if (setter.IsPrivate || setter.IsFamily)
continue;
// Skip static properties and indexers.
if (propertyMethod.IsStatic || p.GetIndexParameters().Length != 0)
return false;
yield return member;
}
return true;
});
#else
return type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.CanWrite && p.GetIndexParameters().Length == 0);
#endif
info = info.BaseType?.GetTypeInfo();
}
}
#endregion
@ -85,29 +82,5 @@ namespace Unity.Processors
}
#endregion
#region Implementation
#if NETSTANDARD1_0
public static IEnumerable<PropertyInfo> GetPropertiesHierarchical(Type type)
{
if (type == null)
{
return Enumerable.Empty<PropertyInfo>();
}
if (type == typeof(object))
{
return type.GetTypeInfo().DeclaredProperties;
}
return type.GetTypeInfo()
.DeclaredProperties
.Concat(GetPropertiesHierarchical(type.GetTypeInfo().BaseType));
}
#endif
#endregion
}
}

Просмотреть файл

@ -88,7 +88,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="System.ValueTuple" Version="4.5.*" />
</ItemGroup>
</Project>

Просмотреть файл

@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.3" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.4" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>

Просмотреть файл

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>

Просмотреть файл

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>