mercredi 16 juin 2021

C# Generic expression tree that targets a method on a class?

I'm trying to make some syntax sugar method that returns a MethodInfo when provided with a Method reference. (My actual goal is fetching custom attributes from some controller actions)

The "vanilla" way to get a method info is:

MethodInfo m = typeof(Foo.API.Controllers.CountryController)
            .GetMethod(nameof(Foo.API.Controllers.CountryController.List)

I want something so I do not have to specify the entire namespace twice. Seriously, if I could use...

MethodInfoOf(Foo.API.Controllers.CountryController.List)

it would be amazing.





Aucun commentaire:

Enregistrer un commentaire