Can I get the signature of a C # delegate by type?

Is there an easy way to use reflection to get a list of parameters for a delegate if you have his type information?

As an example, if I declare a delegate type as follows

delegate double FooDelegate (string param, bool condition); 

and then get the type information for this type of delegate as follows

 Type delegateType = typeof(FooDelegate); 

Is it possible to get a return type (double) and a list of parameters ({string, bool}) from this type information object?

+49
reflection c # delegates
Jan 9 '09 at 20:16
source share
1 answer
  MethodInfo method = delegateType.GetMethod("Invoke"); Console.WriteLine(method.ReturnType.Name + " (ret)"); foreach (ParameterInfo param in method.GetParameters()) { Console.WriteLine("{0} {1}", param.ParameterType.Name, param.Name); } 
+90
Jan 09 '09 at 20:19
source share



All Articles