1

I am writing tests to ensure that certain classes have extension methods only. So I want to make sure that my methods all look like this:

public <someType> MethodName (this <Type> something, <0 or more params) 
{ 
}

Unfortunately, I haven't found a way to test whether the first parameter of the method has the 'this' prefix stuck to it.

bool IsExtensionMethod (MethodInfo methodInfo) {
  var parameter = methodInfo.GetParameters();
  return parameter.Any() && IsThisParameter(parameter[0]);
  }

bool IsThisParameter (ParameterInfo parameterInfo) {
  return parameterInfo.?????
}

Any ideas?

alzaimar
  • 4,572
  • 1
  • 16
  • 30
  • 1
    Remember, extension methods are just sugary static methods with some extra rules about their containing classes. I believe the `ExtensionAttribute` is the only difference once compiled. – Jonathon Chase Feb 04 '19 at 18:17
  • Awesome! Thanks for pointing out that this is a duplicate. I was too narrow minded as to think of looking for the more general but obvious quiestion "Is it an extension method" – alzaimar Feb 04 '19 at 18:22

0 Answers0