Skip to content

Commit

Permalink
Feature: allow interception of any generic method call when using Arg…
Browse files Browse the repository at this point in the history
….AnyType
  • Loading branch information
JMolenkamp committed Dec 13, 2024
1 parent dfef728 commit 1fcbcde
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/NSubstitute/Core/CallInfo.cs
Original file line number Diff line number Diff line change
@@ -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)
{

/// <summary>
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/NSubstitute/Core/CallInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/NSubstitute/Core/CallSpecification.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;
using NSubstitute.Core.Arguments;
using System.Reflection;

namespace NSubstitute.Core;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 1fcbcde

Please sign in to comment.