// Determine if two method builders are equal. public override bool Equals(Object obj) { MethodBuilder mb = (obj as MethodBuilder); if (mb != null) { if (Name != mb.Name) { return(false); } if (Attributes != mb.Attributes) { return(false); } if (ReturnType != mb.ReturnType) { return(false); } ParameterInfo[] params1 = GetParameters(); ParameterInfo[] params2 = mb.GetParameters(); if (params1.Length != params2.Length) { return(false); } int index; for (index = 0; index < params1.Length; ++index) { if (params1[index].Attributes != params2[index].Attributes) { return(false); } if (params1[index].ParameterType != params2[index].ParameterType) { return(false); } } return(true); } else { return(false); } }
public static object Invoke (Type type, MethodBuilder methodBuilder, params object[] parameters) { var method = type.GetMethods ().First (m => { if (m.Name != methodBuilder.Name) return false; var params1 = m.GetParameters (); var params2 = methodBuilder.GetParameters (); if (params1.Length != params2.Length) return false; for (var i = 0; i < params1.Length; i++) if (params1 [i].ParameterType.FullName != params2 [i].ParameterType.FullName) return false; return true; }); object inst = Activator.CreateInstance (type, new object [0]); return method.Invoke (inst, parameters); }