public static MethodInfo GetMethod(string name, Type[] types = null, bool @public = true, bool instance = true) { if (name == null) { throw new ArgumentNullException("name"); } types = types ?? Types.None; var flags = GetFlags(@public, instance); var key = new MethodInfoKey(name, flags, types); MethodInfo result; if (!methodCache.TryGetValue(key, out result)) { result = Type.GetMethod(name, flags, binder: null, types: types, modifiers: null); if (result == null) { throw new ReflectionException(GetNotFoundMessage("method", name)); } methodCache.Add(key, result); } return(result); }
/// <devdoc> /// Determines if this object is equal to /// another. MethodInfoKey's are considered /// equal if the methods within them are /// compatible with respect to name and /// parameters. /// </devdoc> public override bool Equals(object obj) { MethodInfoKey theirMethodInfoKey = obj as MethodInfoKey; if (theirMethodInfoKey == null) { return(false); } MethodInfo theirMethod = theirMethodInfoKey.method; if (!method.Name.Equals(theirMethod.Name)) { return(false); } ParameterInfo[] ourParameters = method.GetParameters(); ParameterInfo[] theirParameters = theirMethod.GetParameters(); if (ourParameters.Length != theirParameters.Length) { return(false); } for (int p = 0; p < ourParameters.Length; p++) { if (!ourParameters[p].ParameterType.Equals(theirParameters[p].ParameterType)) { return(false); } } return(true); }