public static MethodInfo GetMethod (Type type, MethodInfo method) { if (!IsValidGetMethodType (type)) throw new ArgumentException ("type is not TypeBuilder but " + type.GetType (), "type"); if (type is TypeBuilder && type.ContainsGenericParameters) type = type.MakeGenericType (type.GetGenericArguments ()); if (!type.IsGenericType) throw new ArgumentException ("type is not a generic type", "type"); if (!method.DeclaringType.IsGenericTypeDefinition) throw new ArgumentException ("method declaring type is not a generic type definition", "method"); if (method.DeclaringType != type.GetGenericTypeDefinition ()) throw new ArgumentException ("method declaring type is not the generic type definition of type", "method"); if (method == null) throw new NullReferenceException (); //MS raises this instead of an ArgumentNullException MethodInfo res = type.GetMethod (method); if (res == null) throw new ArgumentException (String.Format ("method {0} not found in type {1}", method.Name, type)); return res; }