static bool MatchesAnyParameter (MethodReference method, string operand) { if (operand == null) return false; // for most getter and setter the property name is used if (method.IsProperty ()) { if (String.Compare (method.Name, 4, operand, 0, operand.Length, StringComparison.Ordinal) == 0) return true; // but we continue looking for parameters (e.g. indexers) unless it's the generic 'value' string if (operand == "value") return false; } // note: we already know there are Parameters for this method is we got here foreach (ParameterDefinition parameter in method.Parameters) { if (parameter.Name == operand) return true; } return false; }
static bool DoesReturnDisposable (MethodReference call) { //ignore properties (likely not the place where the IDisposable is *created*) MethodDefinition method = call.Resolve (); if ((method == null) || call.IsProperty ()) return false; if (method.IsConstructor) { if (method.DeclaringType.IsGeneratedCode ()) return false; //eg. generators return method.DeclaringType.Implements ("System", "IDisposable"); } return method.ReturnType.Implements ("System", "IDisposable"); }