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,
To get the return type property, first get the class Type . From the Type , get the MethodInfo . From the MethodInfo , get the ReturnType .
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With