lundi 4 février 2019

Check whether a parameter has the 'this' prefix

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?





Aucun commentaire:

Enregistrer un commentaire