I’m programming in Unity, using an Action event to hold a bunch of other Action delegates, in order to hook non-Monobehaviour objects into the Update() system. I’d like to be able to print the names of the actions to the Debug console, but using something like:
Delegate[] actions = updateActions.GetInvocationList();
foreach ( Delegate del in actions ) {
Debug.Log( del.ToString() );
}
… just returns “System.Action”. I’ve tried also (del as Action).ToString() with no luck.
You can use the
Methodproperty to get aMethodInfowhich should have a useful name.You can use
del.Method.ToString()if you want the signature ordel.Method.Nameif you only want the name.del.Method.ReflectedType.FullNamegives you the type name.For lambdas/anonymous methods the name might not be too useful since they only have a compiler generated name. In the current implementation the name of a lambda is something like
<Main>b__0whereMainis the name of the method that contains the lambda. Together with the type name this should give you a decent idea which lambda it is.