-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[API Proposal]: Add overload of Type.GetMethod
that takes a name, generic parameter count, binding flags and parameter types
#90995
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsBackground and motivationIn #42753, an overload of API Proposal namespace System;
public abstract partial class Type
{
public System.Reflection.MethodInfo? GetMethod(string name) { throw null; }
public System.Reflection.MethodInfo? GetMethod(string name, int genericParameterCount, System.Type[] types) { throw null; }
public System.Reflection.MethodInfo? GetMethod(string name, int genericParameterCount, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; }
+ public System.Reflection.MethodInfo? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, System.Type[] types) { throw null; }
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; }
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; }
public System.Reflection.MethodInfo? GetMethod(string name, System.Type[] types) { throw null; }
public System.Reflection.MethodInfo? GetMethod(string name, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; }
public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr) { throw null; }
public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Type[] types) { throw null; }
public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; }
public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; }
} API Usageusing System.Reflection;
var method = typeof(C).GetMethod("M", 0, BindingFlags.Public | BindingFlags.Instance, Array.Empty<Type>());
class C
{
public void M();
} Alternative DesignsNo response RisksNo response
|
Type.GetMethod
that takes a name, generic parameter count, binding flags and parameter types
Type.GetMethod
that takes a name, generic parameter count, binding flags and parameter typesType.GetMethod
that takes a name, generic parameter count, binding flags and parameter types
The original request would help the common cases: public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Type[] types); However, I'm not so sure about the other 2 since they remove the |
Right, I'm only interested in that one, I just added the proposal for the rest of them only as an idea if parity and consistency is desired. |
I think it makes sense to add this to v9: public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Type[] types); |
I'd be interested in taking this up if it gets through the API review :) |
Looks good as proposed. namespace System;
public abstract partial class Type
{
public MethodInfo? GetMethod(string name, int genericParameterCount, Type[] types);
public MethodInfo? GetMethod(string name, int genericParameterCount, Type[] types, ParameterModifier[]? modifiers);
+ public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Type[] types);
public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers);
public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers);
public MethodInfo? GetMethod(string name);
public MethodInfo? GetMethod(string name, Type[] types);
public MethodInfo? GetMethod(string name, Type[] types, ParameterModifier[]? modifiers);
public MethodInfo? GetMethod(string name, BindingFlags bindingAttr);
public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Type[] types);
public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers);
public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers);
} |
Background and motivation
In #42753, an overload of
Type.GetMethod
was added that takes a name, binding flags, and paramater types, to simplify usage when people don't care about the binder and paramater modifiers (which as I understand is there only for COM), which basically nobody passes in ever. However no equivalent overload was added that also takes genericParameterCount at the beginning. This is the overload I always use, even when the method isn't generic and I pass in 0, to be as specific as possible and make sure that my code still works even in case there is a generic overload added in the future. It seems that all the other overloads have an equivalent that takes genericParameterCount at the beginning, so this would just square off the feature in my opinion.API Proposal
namespace System; public abstract partial class Type { public MethodInfo? GetMethod(string name, int genericParameterCount, Type[] types); public MethodInfo? GetMethod(string name, int genericParameterCount, Type[] types, ParameterModifier[]? modifiers); + public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Type[] types); public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers); public MethodInfo? GetMethod(string name, int genericParameterCount, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers); public MethodInfo? GetMethod(string name); public MethodInfo? GetMethod(string name, Type[] types); public MethodInfo? GetMethod(string name, Type[] types, ParameterModifier[]? modifiers); public MethodInfo? GetMethod(string name, BindingFlags bindingAttr); public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Type[] types); public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers); public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers); }
API Usage
Alternative Designs
Original issue alternative (not proposed): optionally, to square off the set of overloads completely, with complete parity between the ones that take genericParameterCount and the ones that don't (7 overloads for each):
Risks
No response
The text was updated successfully, but these errors were encountered: