diff --git a/Source/Extensions.cs b/Source/Extensions.cs index 44fb2fd80..207277c31 100644 --- a/Source/Extensions.cs +++ b/Source/Extensions.cs @@ -269,7 +269,7 @@ public static TAttribute GetCustomAttribute(this ICustomAttributePro } #endif - public static bool HasMatchingParameterTypes(this MethodInfo method, Type[] paramTypes) + public static bool HasCompatibleParameterTypes(this MethodInfo method, Type[] paramTypes) { var types = method.GetParameterTypes().ToArray(); if (types.Length != paramTypes.Length) @@ -279,7 +279,12 @@ public static bool HasMatchingParameterTypes(this MethodInfo method, Type[] para for (int i = 0; i < types.Length; i++) { - if (types[i] != paramTypes[i]) + var parameterType = paramTypes[i]; + if (parameterType == typeof(object)) + { + continue; + } + else if (!types[i].IsAssignableFrom(parameterType)) { return false; } diff --git a/Source/Protected/ProtectedMock.cs b/Source/Protected/ProtectedMock.cs index 33f50922c..2c22661d5 100644 --- a/Source/Protected/ProtectedMock.cs +++ b/Source/Protected/ProtectedMock.cs @@ -192,7 +192,7 @@ private static MethodInfo GetMethod(string methodName, params object[] args) { var argTypes = ToArgTypes(args); return typeof(T).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) - .SingleOrDefault(m => m.Name == methodName && m.HasMatchingParameterTypes(argTypes)); + .SingleOrDefault(m => m.Name == methodName && m.HasCompatibleParameterTypes(argTypes)); } private static Expression> GetMethodCall(MethodInfo method, object[] args)