Skip to content

Commit

Permalink
Releasing 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Mar 2, 2019
1 parent d51f265 commit bb97774
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<VersionBase>4.0.3</VersionBase>
<VersionBase>4.1.0</VersionBase>
<TargetFrameworks>netstandard2.0;netstandard1.0;netcoreapp2.0;netcoreapp1.0;net47;net46;net45;net40</TargetFrameworks>
</PropertyGroup>

Expand Down
9 changes: 3 additions & 6 deletions src/Dependency/Injection/Members/InjectionConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ protected override ConstructorInfo SelectMember(Type type, InjectionMember _)

public override IEnumerable<ConstructorInfo> DeclaredMembers(Type type)
{
#if NETCOREAPP1_0 || NETSTANDARD1_0
return type.GetTypeInfo().DeclaredConstructors
.Where(c => c.IsStatic == false && c.IsPublic);
#else
return type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
#endif
return type.GetTypeInfo()
.DeclaredConstructors
.Where(ctor => !ctor.IsFamily && !ctor.IsPrivate && !ctor.IsStatic);
}

public override string ToString()
Expand Down
19 changes: 4 additions & 15 deletions src/Dependency/Injection/Members/InjectionField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,12 @@ protected override FieldInfo DeclaredMember(Type type, string name)

public override IEnumerable<FieldInfo> DeclaredMembers(Type type)
{
#if NETCOREAPP1_0 || NETSTANDARD1_0
if (type == null)
foreach (var member in type.GetDeclaredFields())
{
return Enumerable.Empty<FieldInfo>();
if (!member.IsFamily && !member.IsPrivate &&
!member.IsInitOnly && !member.IsStatic)
yield return member;
}

var info = type.GetTypeInfo();
if (type == typeof(object))
{
return info.DeclaredFields;
}

return info.DeclaredFields
.Concat(DeclaredMembers(type.GetTypeInfo().BaseType));
#else
return type.GetFields(BindingFlags.Instance | BindingFlags.Public);
#endif
}

protected override Type MemberType => Selection.FieldType;
Expand Down
19 changes: 4 additions & 15 deletions src/Dependency/Injection/Members/InjectionMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,12 @@ protected override MethodInfo SelectMember(Type type, InjectionMember _)

public override IEnumerable<MethodInfo> DeclaredMembers(Type type)
{
#if NETCOREAPP1_0 || NETSTANDARD1_0
if (null == type) return Enumerable.Empty<MethodInfo>();

var info = type.GetTypeInfo();
if (typeof(object) == info.DeclaringType)
foreach (var member in type.GetDeclaredMethods())
{
return info.DeclaredMethods.Where(m => !m.IsStatic)
.Where(m => Name == m.Name);
if (!member.IsFamily && !member.IsPrivate &&
!member.IsStatic && member.Name == Name)
yield return member;
}

return info.DeclaredMethods.Where(m => !m.IsStatic)
.Concat(DeclaredMembers(info.BaseType))
.Where(m => Name == m.Name);
#else
return type.GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(m => Name == m.Name);
#endif
}

public override string ToString()
Expand Down
28 changes: 9 additions & 19 deletions src/Dependency/Injection/Members/InjectionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,22 @@ public InjectionProperty(string name, object value)

protected override PropertyInfo DeclaredMember(Type type, string name)
{
#if NETSTANDARD1_0 || NETCOREAPP1_0
return type.GetTypeInfo().GetDeclaredProperty(Selection.Name);
#else
return type.GetProperty(Selection.Name);
#endif
return DeclaredMembers(type).FirstOrDefault(p => p.Name == Selection.Name);
}

public override IEnumerable<PropertyInfo> DeclaredMembers(Type type)
{
#if NETCOREAPP1_0 || NETSTANDARD1_0
if (type == null)
foreach (var member in type.GetDeclaredProperties())
{
return Enumerable.Empty<PropertyInfo>();
}
if (!member.CanWrite || 0 != member.GetIndexParameters().Length)
continue;

var info = type.GetTypeInfo();
if (type == typeof(object))
{
return info.DeclaredProperties;
}
var setter = member.GetSetMethod(true);
if (setter.IsPrivate || setter.IsFamily)
continue;

return info.DeclaredProperties
.Concat(DeclaredMembers(type.GetTypeInfo().BaseType));
#else
return type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
#endif
yield return member;
}
}

protected override Type MemberType => Selection.PropertyType;
Expand Down
37 changes: 37 additions & 0 deletions src/Extensions/Reflection/TypeReflectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Unity
Expand All @@ -18,5 +19,41 @@ public static Type GetArrayParameterType(this Type typeToReflect, Type[] generic

return 1 == rank ? type.MakeArrayType() : type.MakeArrayType(rank);
}

public static IEnumerable<FieldInfo> GetDeclaredFields(this Type type)
{
var info = type.GetTypeInfo();
while (null != info)
{
foreach (var member in info.DeclaredFields)
yield return member;

info = info.BaseType?.GetTypeInfo();
}
}

public static IEnumerable<PropertyInfo> GetDeclaredProperties(this Type type)
{
var info = type.GetTypeInfo();
while (null != info)
{
foreach (var member in info.DeclaredProperties)
yield return member;

info = info.BaseType?.GetTypeInfo();
}
}

public static IEnumerable<MethodInfo> GetDeclaredMethods(this Type type)
{
var info = type.GetTypeInfo();
while (null != info)
{
foreach (var member in info.DeclaredMethods)
yield return member;

info = info.BaseType?.GetTypeInfo();
}
}
}
}

0 comments on commit bb97774

Please sign in to comment.