Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Mar 1, 2019
1 parent c4b5242 commit b4113b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/Dependency/Resolution/Overrides/DependencyOverride.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection;

namespace Unity.Resolution
{
Expand All @@ -9,6 +10,9 @@ namespace Unity.Resolution
/// </summary>
public class DependencyOverride : ResolverOverride,
IEquatable<(Type,string)>,
IEquatable<FieldInfo>,
IEquatable<PropertyInfo>,
IEquatable<ParameterInfo>,
IResolve
{
#region Fields
Expand Down Expand Up @@ -71,6 +75,24 @@ public bool Equals((Type, string) other)
(null == Name || other.Item2 == Name);
}

public bool Equals(FieldInfo other)
{
return (null == Type || other.FieldType == Type) &&
(null == Name || other.Name == Name);
}

public bool Equals(PropertyInfo other)
{
return (null == Type || other.PropertyType == Type) &&
(null == Name || other.Name == Name);
}

public bool Equals(ParameterInfo other)
{
return (null == Type || other.ParameterType == Type) &&
(null == Name || other.Name == Name);
}

#endregion


Expand Down
23 changes: 18 additions & 5 deletions src/Extensions/Injection/Override.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static partial class Override
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static ResolverOverride Parameter<TType>(object value)
=> Parameter(typeof(TType), value);
=> new ParameterOverride(typeof(TType), value);

#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -57,20 +57,33 @@ public static ResolverOverride Parameter(string name, object value)
#endregion



#region Dependency

#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static ResolverOverride Dependency(string name, object value)
public static ResolverOverride Dependency<TType>(object value)
=> new DependencyOverride(typeof(TType), value);

#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static ResolverOverride Dependency<TType>(string name, object value)
=> new DependencyOverride(typeof(TType), name, value);

#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static ResolverOverride Dependency(string name, object value)
=> Dependency(value?.GetType() ?? throw new ArgumentNullException(nameof(value)), name, value);

#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static ResolverOverride Dependency<TType>(string name, object value)
=> Dependency(typeof(TType), name, value);
public static ResolverOverride Dependency(Type type, object value)
{
return new DependencyOverride(type, value);
}

#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit b4113b6

Please sign in to comment.