Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the return type of a method with System.Reflection.MethodBase in C#?

how do I find out the return type of a method from the MethodBase? I'm using PostSharp and trying to override the CompileTimeValidate(MethodBase method) method to make sure the attribute is applied to a method with the correct signature.

Thanks,

like image 366
theburningmonk Avatar asked Mar 22 '10 18:03

theburningmonk


People also ask

How to get return type of a method in c#?

To get the return type property, first get the class Type . From the Type , get the MethodInfo . From the MethodInfo , get the ReturnType .

How do you call MethodInfo?

To invoke a static method using its MethodInfo object, pass null for obj . If this method overload is used to invoke an instance constructor, the object supplied for obj is reinitialized; that is, all instance initializers are executed. The return value is null .


1 Answers

MethodBase is used as a base class of MethodInfo which has a property ReturnType.

You could try and cast to an instance of MethodInfo and check that property.

like image 115
JoshBerke Avatar answered Oct 09 '22 15:10

JoshBerke