How can I get a protected method via reflection matching name and parameters type?

ferodss

Before dotnet core we were able to do

var member = type.GetMethod(name, bindingFlags, null, argtypes, null);

To get access to a method matching its name and parameters type, in dotnet core they removed this overload, now I can only get by name && binding flags OR name && parameters type (see), but not like before.

There is a new method GetRuntimeMethods which returns IEnumerable<MethodInfo> and includes non public methods but I can't filter by parameters type.

There is another method GetRuntimeMethod which I can filter by parameters type but it doesn't include non public methods.

I already tried something like this, but fails

var member = type.GetRuntimeMethods().Where(m =>
m.Name == name && (m.GetParameters().Select(p => p.GetType()).ToArray() == argtypes)).FirstOrDefault();

Is there a way to get a method by its name and parameters type?

svick

Yes, that overload is indeed missing. What you can use is to use GetMethods() and filter the output the way you want. Your attempt is close, except you can't compare arrays using ==:

var method = type.GetMethods().FirstOrDefault(m =>
    m.Name == name && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(argTypes));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I get a constructor's parameters via reflection in Dart?

From Dev

How can I get a constructor's parameters via reflection in Dart?

From Dev

In Scala, how to use reflection to get the real type of varargs parameters for method

From Dev

How can I Get the property by name from type and Set Propert value using reflection in C#

From Dev

how to get the overriden version of a protected method in java through reflection?

From Dev

How to get generic argument name via reflection

From Dev

smalltalk reflection - how to get method name?

From Dev

Get only protected members via .net reflection

From Dev

Can I get a method by signature, using reflection?

From Dev

How can I check that method parameters have the same type as the methods this?

From Dev

Can I find a method with generic parameters using strongly typed reflection?

From Dev

How can I tell if a C# method is async/await via reflection?

From Dev

How can I find out what a method's visibility is via reflection?

From Dev

How to use Reflection GetMethods on protected readonly method

From Dev

Get shadowed method via reflection

From Dev

How do I get the type name passed in a generic method call?

From Dev

can we get author name,method purpose using java reflection

From Dev

How can I get a constructor for a type when one of the parameters is dynamic?

From Dev

How can I get a constructor for a type when one of the parameters is dynamic?

From Dev

Can I obtain method Fields name using Java reflection?

From Dev

How can I set protected mode of internet options via cmd

From Dev

How can I get the name of the currently executing Meteor method?

From Dev

How can a generic base type be cast via reflection in Java?

From Dev

How can a generic base type be cast via reflection in Java?

From Dev

How can i get the name of the interface, its type and ip?

From Dev

How to get Fully Qualified Name of a Type using Reflection in C#

From Dev

Java, method name via reflection for logging

From Dev

How can I get the generic type parameter of the 'this' parameter in an extension method?

From Dev

How can I get the generic type parameter of the 'this' parameter in an extension method?

Related Related

  1. 1

    How can I get a constructor's parameters via reflection in Dart?

  2. 2

    How can I get a constructor's parameters via reflection in Dart?

  3. 3

    In Scala, how to use reflection to get the real type of varargs parameters for method

  4. 4

    How can I Get the property by name from type and Set Propert value using reflection in C#

  5. 5

    how to get the overriden version of a protected method in java through reflection?

  6. 6

    How to get generic argument name via reflection

  7. 7

    smalltalk reflection - how to get method name?

  8. 8

    Get only protected members via .net reflection

  9. 9

    Can I get a method by signature, using reflection?

  10. 10

    How can I check that method parameters have the same type as the methods this?

  11. 11

    Can I find a method with generic parameters using strongly typed reflection?

  12. 12

    How can I tell if a C# method is async/await via reflection?

  13. 13

    How can I find out what a method's visibility is via reflection?

  14. 14

    How to use Reflection GetMethods on protected readonly method

  15. 15

    Get shadowed method via reflection

  16. 16

    How do I get the type name passed in a generic method call?

  17. 17

    can we get author name,method purpose using java reflection

  18. 18

    How can I get a constructor for a type when one of the parameters is dynamic?

  19. 19

    How can I get a constructor for a type when one of the parameters is dynamic?

  20. 20

    Can I obtain method Fields name using Java reflection?

  21. 21

    How can I set protected mode of internet options via cmd

  22. 22

    How can I get the name of the currently executing Meteor method?

  23. 23

    How can a generic base type be cast via reflection in Java?

  24. 24

    How can a generic base type be cast via reflection in Java?

  25. 25

    How can i get the name of the interface, its type and ip?

  26. 26

    How to get Fully Qualified Name of a Type using Reflection in C#

  27. 27

    Java, method name via reflection for logging

  28. 28

    How can I get the generic type parameter of the 'this' parameter in an extension method?

  29. 29

    How can I get the generic type parameter of the 'this' parameter in an extension method?

HotTag

Archive