diff --git a/src/Builder/Context/BuilderContext.cs b/src/Builder/Context/BuilderContext.cs index 8763b5bb3..add9e873f 100644 --- a/src/Builder/Context/BuilderContext.cs +++ b/src/Builder/Context/BuilderContext.cs @@ -4,6 +4,7 @@ using System.Runtime.CompilerServices; using System.Security; using Unity.Exceptions; +using Unity.Injection; using Unity.Lifetime; using Unity.Policy; using Unity.Registration; @@ -55,7 +56,7 @@ public object Resolve(Type type, string name) var resolverOverride = Overrides[index]; // If matches with current parameter if (resolverOverride is IResolve resolverPolicy && - resolverOverride is IEquatable comparer && comparer.Equals(namedType)) + resolverOverride is IMatch comparer && comparer.Match(namedType)) { var context = this; @@ -191,7 +192,7 @@ public object Resolve(ParameterInfo parameter, object value) var resolverOverride = Overrides[index]; // If matches with current parameter - if (resolverOverride is IEquatable comparer && comparer.Equals(parameter)) + if (resolverOverride is IMatch comparer && comparer.Match(parameter)) { // Check if itself is a value if (resolverOverride is IResolve resolverPolicy) @@ -236,7 +237,7 @@ public object Resolve(PropertyInfo property, object value) var resolverOverride = Overrides[index]; // Check if this parameter is overridden - if (resolverOverride is IEquatable comparer && comparer.Equals(property)) + if (resolverOverride is IMatch comparer && comparer.Match(property)) { // Check if itself is a value if (resolverOverride is IResolve resolverPolicy) @@ -291,7 +292,7 @@ public object Resolve(FieldInfo field, object value) var resolverOverride = Overrides[index]; // Check if this parameter is overridden - if (resolverOverride is IEquatable comparer && comparer.Equals(field)) + if (resolverOverride is IMatch comparer && comparer.Match(field)) { // Check if itself is a value if (resolverOverride is IResolve resolverPolicy) diff --git a/src/Legacy/TypeBasedOverride.cs b/src/Legacy/TypeBasedOverride.cs index 61cc13368..3d738b0bd 100644 --- a/src/Legacy/TypeBasedOverride.cs +++ b/src/Legacy/TypeBasedOverride.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using Unity.Injection; namespace Unity.Resolution { @@ -11,9 +12,9 @@ namespace Unity.Resolution /// [Obsolete("This type has been deprecated as degrading performance. Use ResolverOverride.OnType() instead.", false)] public class TypeBasedOverride : ResolverOverride, - IEquatable, - IEquatable, - IEquatable + IMatch, + IMatch, + IMatch { #region Constructors @@ -43,22 +44,22 @@ public override bool Equals(object obj) return Value.Equals(obj); } - public bool Equals(FieldInfo other) + public bool Match(FieldInfo other) { - return Value is IEquatable info && - info.Equals(other); + return Value is IMatch info && + info.Match(other); } - public bool Equals(PropertyInfo other) + public bool Match(PropertyInfo other) { - return Value is IEquatable info && - info.Equals(other); + return Value is IMatch info && + info.Match(other); } - public bool Equals(ParameterInfo other) + public bool Match(ParameterInfo other) { - return Value is IEquatable info && - info.Equals(other); + return Value is IMatch info && + info.Match(other); } #endregion diff --git a/tests/Unity.Tests/Generics/GenericResolvedArrayParameterFixture.cs b/tests/Unity.Tests/Generics/GenericResolvedArrayParameterFixture.cs index 4c13f9ddd..2b77a04bf 100644 --- a/tests/Unity.Tests/Generics/GenericResolvedArrayParameterFixture.cs +++ b/tests/Unity.Tests/Generics/GenericResolvedArrayParameterFixture.cs @@ -11,7 +11,7 @@ public class GenericResolvedArrayParameterFixture [TestMethod] public void MatchesArrayOfGenericTypeOnly() { - var parameterValue = (IEquatable)new GenericResolvedArrayParameter("T"); + var parameterValue = (IMatch)new GenericResolvedArrayParameter("T"); Type genericTypeT = this.GetType().GetTypeInfo().GetDeclaredMethod("GetT") @@ -20,13 +20,13 @@ Type genericTypeU = this.GetType().GetTypeInfo().GetDeclaredMethod("GetU") .GetGenericArguments()[0]; - Assert.IsFalse(parameterValue.Equals(genericTypeT)); - Assert.IsFalse(parameterValue.Equals(genericTypeU)); - Assert.IsFalse(parameterValue.Equals(typeof(object))); - Assert.IsTrue( parameterValue.Equals(genericTypeT.MakeArrayType(1))); - Assert.IsFalse(parameterValue.Equals(genericTypeT.MakeArrayType(2))); - Assert.IsFalse(parameterValue.Equals(genericTypeU.MakeArrayType(1))); - Assert.IsFalse(parameterValue.Equals(typeof(object[]))); + Assert.IsFalse(parameterValue.Match(genericTypeT)); + Assert.IsFalse(parameterValue.Match(genericTypeU)); + Assert.IsFalse(parameterValue.Match(typeof(object))); + Assert.IsTrue( parameterValue.Match(genericTypeT.MakeArrayType(1))); + Assert.IsFalse(parameterValue.Match(genericTypeT.MakeArrayType(2))); + Assert.IsFalse(parameterValue.Match(genericTypeU.MakeArrayType(1))); + Assert.IsFalse(parameterValue.Match(typeof(object[]))); } [TestMethod]