Extension methods are just static methods, compiler translates this call
yourEnum.Test();
to:
MyClass.Test(yourEnum);
So in order to get Test
method info via reflection, you need to inspect MyClass
, ActivityStatus
is just a parameter there.
var testMethodInfo = typeof(MyClass).GetMethod("Test");
var firstParameter = testMethodInfo.GetParameters()[0];
Console.WriteLine (firstParameter.ParameterType + " " + firstParameter.Name);
prints:
ActivityStatus _value
If you want to get all extension methods for type in a particular assembly, you can use next code:
var extensionMethodsForActivityStatus =
typeof(ActivityStatus) //type from assembly to search
.Assembly //pick an assembly
.GetTypes() //get all types there
.SelectMany(t => t.GetMethods()) //get all methods for that type
.Where(m => m.GetParameters().Any() &&
m.GetParameters().First().ParameterType == typeof(ActivityStatus)) //check if first parameter is our enum
.Where(m => m.IsDefined(typeof(ExtensionAttribute), true)); //check if the method is an extension method
foreach(var extensionMethod in extensionMethodsForActivityStatus)
Console.WriteLine(extensionMethod.Name); //prints only Test