public ITargetMethod[] GetAllMethods() { List <ITargetMethod> methods = new List <ITargetMethod>(); if (_target != null) { MethodInfo[] members = _target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < members.Length; i++) { MethodInfo member = members[i]; object[] customAttributes = member.GetCustomAttributes(typeof(TargetMethodAttribute), true); if (customAttributes != null && customAttributes.Length > 0) { TargetMethodAttribute targetMethodAttribute = customAttributes[0] as TargetMethodAttribute; TargetMethod targetMethod = new TargetMethod(_target, member, targetMethodAttribute.Method, targetMethodAttribute.Overload); methods.Add(targetMethod); } } } return(methods.ToArray()); }
public ITargetMethod GetMethod(string methodName, int overload) { ITargetMethod targetMethod = null; if (_target != null) { MethodInfo[] members = _target.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < members.Length; i++) { MethodInfo member = members[i]; object[] customAttributes = member.GetCustomAttributes(typeof(TargetMethodAttribute), true); if (customAttributes != null && customAttributes.Length > 0) { TargetMethodAttribute targetMethodAttribute = customAttributes[0] as TargetMethodAttribute; if (targetMethodAttribute.Method.Equals(methodName) && targetMethodAttribute.Overload == overload) { targetMethod = new TargetMethod(_target, member, targetMethodAttribute.Method, targetMethodAttribute.Overload); } } } } return(targetMethod); }