Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type.GetMethod(name, genericParameterCount, bindingAttr, types) overload #94889

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private static RuntimeMethodInfo LookupMethodForCreateDelegate(RuntimeTypeInfo r
Type? type = containingType.ToType();
while (type != null)
{
MethodInfo? methodInfo = type.GetMethod(method, 0, bindingFlags, null, parameterTypes, null);
MethodInfo? methodInfo = type.GetMethod(method, 0, bindingFlags, parameterTypes);
if (methodInfo != null && methodInfo.ReturnType.Equals(invokeMethod.ReturnType))
return (RuntimeMethodInfo)methodInfo; // This cast is safe since we already verified that containingType is runtime implemented.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static void AddMethod(this Dictionary<MethodBase, CustomMethodInvokerAct
}
else
{
methodBase = declaringType.GetMethod(name, 0, bf, null, parameterTypes, null);
methodBase = declaringType.GetMethod(name, 0, bf, parameterTypes);
}

if (methodBase == null)
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ private protected static ArgumentException CreateGetMemberWithSameMetadataDefini
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
public MethodInfo? GetMethod(string name, int genericParameterCount, Type[] types, ParameterModifier[]? modifiers) => GetMethod(name, genericParameterCount, DefaultLookup, null, types, modifiers);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Type[] types) => GetMethod(name, genericParameterCount, bindingAttr, null, types, null);

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers) => GetMethod(name, genericParameterCount, bindingAttr, binder, CallingConventions.Any, types, modifiers);

Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6164,6 +6164,8 @@ protected Type() { }
public System.Reflection.MethodInfo? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)]
public System.Reflection.MethodInfo? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)]
public System.Reflection.MethodInfo? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, System.Type[] types) { throw null; }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)]
public System.Reflection.MethodInfo? GetMethod(string name, int genericParameterCount, System.Type[] types) { throw null; }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void GetMethodWithGenericParameterCount()

for (int genericParameterCount = 0; genericParameterCount < 4; genericParameterCount++)
{
m = t.GetMethod("Moo", genericParameterCount, bf, null, args, null);
m = t.GetMethod("Moo", genericParameterCount, bf, args);
Assert.NotNull(m);
AssertIsMarked(m, genericParameterCount);

Expand All @@ -74,7 +74,7 @@ public static void GetMethodWithGenericParameterCount()
AssertIsMarked(m, genericParameterCount);
}

m = t.GetMethod("Moo", 4, bf, null, args, null);
m = t.GetMethod("Moo", 4, bf, args);
Assert.Null(m);
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public static void GetMethodWithNegativeGenericParameterCount()
Type t = typeof(TestClass1);
const BindingFlags bf = BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly;
Type[] args = { typeof(int) };
AssertExtensions.Throws<ArgumentOutOfRangeException>("genericParameterCount", () => t.GetMethod("Moo", -1, bf, null, args, null));
AssertExtensions.Throws<ArgumentOutOfRangeException>("genericParameterCount", () => t.GetMethod("Moo", -1, bf, args));
}

[Theory]
Expand Down
Loading