diff --git a/src/NSubstitute/Core/CallInfo.cs b/src/NSubstitute/Core/CallInfo.cs index 63ac178e..8e5adae2 100644 --- a/src/NSubstitute/Core/CallInfo.cs +++ b/src/NSubstitute/Core/CallInfo.cs @@ -1,12 +1,13 @@ -using System.Diagnostics.CodeAnalysis; using NSubstitute.Exceptions; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; // Disable nullability for entry-point API #nullable disable annotations namespace NSubstitute.Core; -public class CallInfo(Argument[] callArguments) +public class CallInfo(Argument[] callArguments, MethodInfo methodInfo) { /// @@ -25,6 +26,8 @@ public object this[int index] } } + public MethodInfo MethodInfo => methodInfo; + private void EnsureArgIsSettable(Argument argument, int index, object value) { if (!argument.IsByRef) diff --git a/src/NSubstitute/Core/CallInfoFactory.cs b/src/NSubstitute/Core/CallInfoFactory.cs index 983c652e..fe14d426 100644 --- a/src/NSubstitute/Core/CallInfoFactory.cs +++ b/src/NSubstitute/Core/CallInfoFactory.cs @@ -5,7 +5,7 @@ public class CallInfoFactory : ICallInfoFactory public CallInfo Create(ICall call) { var arguments = GetArgumentsFromCall(call); - return new CallInfo(arguments); + return new CallInfo(arguments, call.GetMethodInfo()); } private static Argument[] GetArgumentsFromCall(ICall call) diff --git a/src/NSubstitute/Core/CallSpecification.cs b/src/NSubstitute/Core/CallSpecification.cs index 7b099a94..3f39b1e9 100644 --- a/src/NSubstitute/Core/CallSpecification.cs +++ b/src/NSubstitute/Core/CallSpecification.cs @@ -1,5 +1,5 @@ -using System.Reflection; using NSubstitute.Core.Arguments; +using System.Reflection; namespace NSubstitute.Core; @@ -93,7 +93,7 @@ internal static bool TypesAreAllEquivalent(Type[] aArgs, Type[] bArgs) private static bool AreEquivalentDefinitions(MethodInfo a, MethodInfo b) { return a.IsGenericMethod == b.IsGenericMethod - && a.ReturnType == b.ReturnType + && TypesAreAllEquivalent([a.ReturnType], [b.ReturnType]) && a.Name.Equals(b.Name, StringComparison.Ordinal); }