0

Lets say I have a func, like the below one...

Func<ISession, IIncomingPacket, IControllerContext, Task>

How would I get the class that the func method belongs to?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
seegal
  • 75
  • 2

1 Answers1

1

Func already has information about the declaring type: myFunc.Method.DeclaringType- see Get MethodInfo for a lambda expression. Note so that really it is useless in most cases as frequently such function will be declared inline at the point of call - you may have to walk up through classes to find something useful.

Func<int, string> f = (i => i.ToString());
Console.Write(f.Method.DeclaringType.Name);

You can't get such information from Func<...> and really it is useless in most cases as frequently such function will be declared inline at the point of call.

Usually to get that information you'd use Expression<...> instead - see How to get Method Name of Generic Func<T> passed into Method for an example.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179