From b4113b62a5f07619407db9b1cf5b7de2989fa414 Mon Sep 17 00:00:00 2001 From: Eugene Sadovoi Date: Fri, 1 Mar 2019 15:47:10 -0500 Subject: [PATCH] Fixed unitycontainer/container#140 --- .../Overrides/DependencyOverride.cs | 22 ++++++++++++++++++ src/Extensions/Injection/Override.cs | 23 +++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/Dependency/Resolution/Overrides/DependencyOverride.cs b/src/Dependency/Resolution/Overrides/DependencyOverride.cs index 4331f5e2..68d8895c 100644 --- a/src/Dependency/Resolution/Overrides/DependencyOverride.cs +++ b/src/Dependency/Resolution/Overrides/DependencyOverride.cs @@ -1,4 +1,5 @@ using System; +using System.Reflection; namespace Unity.Resolution { @@ -9,6 +10,9 @@ namespace Unity.Resolution /// public class DependencyOverride : ResolverOverride, IEquatable<(Type,string)>, + IEquatable, + IEquatable, + IEquatable, IResolve { #region Fields @@ -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 diff --git a/src/Extensions/Injection/Override.cs b/src/Extensions/Injection/Override.cs index c56d3b21..e93b2057 100644 --- a/src/Extensions/Injection/Override.cs +++ b/src/Extensions/Injection/Override.cs @@ -28,7 +28,7 @@ public static partial class Override [MethodImpl(MethodImplOptions.AggressiveInlining)] #endif public static ResolverOverride Parameter(object value) - => Parameter(typeof(TType), value); + => new ParameterOverride(typeof(TType), value); #if !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -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(object value) + => new DependencyOverride(typeof(TType), value); + + #if !NET40 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + public static ResolverOverride Dependency(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(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)]