Reputation: 1478
public static string GetFuncName<T1, T2>(Func<T1, T2> func){
return func.Method.Name;
}
I use this code can get "string function(string)
" structure method name.
But I can't get "void function()
" structure method name.
"GetFuncName(xxx)" throws volid error.
I need get the "void function()
" name finally.
Upvotes: 0
Views: 244
Reputation: 43523
You can always get the method name via Delegate.Method.Name
. IMO your method is not necessary to be generic.
public static string GetDelegateName(Delegate instance)
{
return instance.Method.Name;
}
Upvotes: 0
Reputation: 23937
For a void you will need an Action<>
type delegate and not a Func delegate.
So you will need another method
public static string GetActionName<T1>(Action<T1> action){
return action.Method.Name;
}
Upvotes: 1