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

theburningmonk picture theburningmonk · Mar 22, 2010 · Viewed 14.9k times · Source

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,

Answer

JoshBerke picture JoshBerke · Mar 22, 2010

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.