jeudi 15 juin 2017

C# Reflection get variable's method nameof

I have selected a static method and assigned it to variable like so:

var reflectionedMethod =
    typeof(MyType)
    .GetMethod(
        nameof(MyMethod),
        BindingFlags.NonPublic 
        | BindingFlags.Public 
        | BindingFlags.Static 
        | BindingFlags.FlattenHierarchy,
        null,
        new Type[] { typeof(TArgs) },
        null);
// IN THIS IF STATEMENT IS THE ACTUAL QUESTION'S PROBLEM 
if (reflectionedMethod == null)
{
    new NotImplementedException(string.Format("{0} not implemented!", nameof(MyMethod)));
}

Question:

What is the best way to get method from a variable (not just like nameof(MyMethod)) into

new NotImplementedException(string.Format("{0} not implemented!", [INSERT HERE SOLUTION PLEASE]));





Aucun commentaire:

Enregistrer un commentaire