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,
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,
Try something like this.
MethodInfo
has the property butMethodBase
is used for constructors as well, and they do not have a return type.Try the
MethodInfo.ReturnType
property.To get the return type property, first get the
Type
. From theType
, get theMethodInfo
. From theMethodInfo
, get theReturnType
.It seems like you can't do it with MethodBase...
http://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.returntype.aspx
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.
MethodBase
itself does not have a return type because in addition to normal methods it also is used to represent methods, such as constructors, which have no return type. Instead you need to see if it's an instance ofMethodInfo
and check that for theReturnType
property.