Skip to content

Commit

Permalink
Releasing v5.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Aug 22, 2018
1 parent 4680c82 commit 091d5cc
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<Version>5.2.3</Version>
<PackageReleaseNotes>This package is compatible with .NET 4.5, 4.6, and 4.7 frameworks.</PackageReleaseNotes>
<Version>5.2.4</Version>
<PackageReleaseNotes>This package is compatible with NET Standard 2.0, Net Core 2.0, .NET 4.0, 4.5, 4.6, and 4.7 frameworks.</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup>
Expand Down
205 changes: 205 additions & 0 deletions src/ConfigurationHelpers/Compatibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
using System.Collections.Generic;
using System.Linq;
using Unity.Attributes;

#if NET40
namespace System.Reflection
{
using Unity;

internal class TypeInfo
{
private const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
private readonly Type _type;


internal TypeInfo(Type type)
{
_type = type ?? throw new ArgumentNullException(nameof(type));
}


public Assembly Assembly => _type.Assembly;

public bool IsGenericTypeDefinition => _type.IsGenericTypeDefinition;

public Type[] GenericTypeArguments => _type.GetGenericArguments();

public Type[] GenericTypeParameters => _type.IsGenericTypeDefinition ? _type.GetGenericArguments()
: Type.EmptyTypes;
public string Name => _type.Name;

public Type BaseType => _type.BaseType;

public bool IsGenericType => _type.IsGenericType;

public Type AsType() => _type;

public bool IsAssignableFrom(TypeInfo typeInfo) => _type.IsAssignableFrom(typeInfo.AsType());

public bool IsGenericParameter => _type.IsGenericParameter;

public bool IsInterface => _type.IsInterface;

public bool IsAbstract => _type.IsAbstract;

public bool IsSubclassOf(Type type) => _type.IsSubclassOf(type);

public bool IsValueType => _type.IsValueType;

public bool ContainsGenericParameters => _type.ContainsGenericParameters;

public bool IsConstructedGenericType => _type.IsGenericType && !_type.ContainsGenericParameters;

#region moved over from Type

//// Fields

public virtual EventInfo GetDeclaredEvent(String name)
{
return _type.GetEvent(name, DeclaredOnlyLookup);
}
public virtual FieldInfo GetDeclaredField(String name)
{
return _type.GetField(name, DeclaredOnlyLookup);
}
public virtual MethodInfo GetDeclaredMethod(String name)
{
return _type.GetMethod(name, DeclaredOnlyLookup);
}

public virtual IEnumerable<MethodInfo> GetDeclaredMethods(String name)
{
foreach (MethodInfo method in _type.GetMethods(DeclaredOnlyLookup))
{
if (method.Name == name)
yield return method;
}
}

public virtual TypeInfo GetDeclaredNestedType(String name)
{
var nt = _type.GetNestedType(name, DeclaredOnlyLookup);
return nt == null ? null : nt.GetTypeInfo();
}

public virtual PropertyInfo GetDeclaredProperty(String name)
{
return _type.GetProperty(name, DeclaredOnlyLookup);
}


//// Properties

public virtual IEnumerable<ConstructorInfo> DeclaredConstructors => _type.GetConstructors(DeclaredOnlyLookup);

public virtual IEnumerable<EventInfo> DeclaredEvents => _type.GetEvents(DeclaredOnlyLookup);

public virtual IEnumerable<FieldInfo> DeclaredFields => _type.GetFields(DeclaredOnlyLookup);

public virtual IEnumerable<MemberInfo> DeclaredMembers => _type.GetMembers(DeclaredOnlyLookup);

public virtual IEnumerable<MethodInfo> DeclaredMethods => _type.GetMethods(DeclaredOnlyLookup);

public virtual IEnumerable<TypeInfo> DeclaredNestedTypes
{
get
{
foreach (var t in _type.GetNestedTypes(DeclaredOnlyLookup))
{
yield return t.GetTypeInfo();
}
}
}

public virtual IEnumerable<PropertyInfo> DeclaredProperties => _type.GetProperties(DeclaredOnlyLookup);


public virtual IEnumerable<Type> ImplementedInterfaces => _type.GetInterfaces();

#endregion

public override int GetHashCode()
{
return _type.GetHashCode();
}

public override bool Equals(object obj)
{
return _type.Equals(obj);
}

public static bool operator ==(TypeInfo left, TypeInfo right)
{
return left?.GetHashCode() == right?.GetHashCode();
}

public static bool operator !=(TypeInfo left, TypeInfo right)
{
return left?.GetHashCode() != right?.GetHashCode();
}

public Type GetGenericTypeDefinition()
{
return _type.GetGenericTypeDefinition();
}
}
}
#endif

namespace Unity
{
using System;
using System.Reflection;


internal static class Compatibility
{
#if NETSTANDARD1_0
public static System.Reflection.ConstructorInfo[] GetConstructors(this System.Type type)
{
var ctors = type.GetTypeInfo().DeclaredConstructors;
return ctors is ConstructorInfo[] array ? array : ctors.ToArray();
}
#endif

#if NET40
public static Attribute GetCustomAttribute(this ParameterInfo parameter, Type type)
{
return parameter.GetCustomAttributes(false)
.OfType<DependencyResolutionAttribute>()
.FirstOrDefault();
}

public static TypeInfo GetTypeInfo(this Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}

return new TypeInfo(type);
}

public static Delegate CreateDelegate(this MethodInfo method, Type delegateType)
{
return Delegate.CreateDelegate(delegateType, method);
}

public static Delegate CreateDelegate(this MethodInfo method, Type delegateType, object target)
{
return Delegate.CreateDelegate(delegateType, target, method);
}
#else
public static MethodInfo GetGetMethod(this PropertyInfo info, bool _)
{
return info.GetMethod;
}

public static MethodInfo GetSetMethod(this PropertyInfo info, bool _)
{
return info.SetMethod;
}
#endif
}
}
3 changes: 2 additions & 1 deletion src/Unity.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>package.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<TargetFrameworks>netstandard2.0;net47;net46;net45;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net47;net46;net45;net40;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -41,6 +41,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<OutputPath>$(SolutionDir)lib</OutputPath>
<DebugType>Portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
6 changes: 3 additions & 3 deletions tests/Configuration.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0-beta2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0-beta2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 091d5cc

Please sign in to comment.