private void UpdateMethodInfo() { this.methodDescriptors.Clear(); if (this.Target != null && !string.IsNullOrEmpty(this.MethodName)) { Type targetType = this.Target.GetType(); MethodInfo[] methods = targetType.GetMethods(BindingFlags.Public | BindingFlags.Instance); for (int i = 0; i < methods.Length; i++) { MethodInfo method = methods[i]; if (!this.IsMethodValid(method)) { continue; } ParameterInfo[] methodParams = method.GetParameters(); if (!CallMethodAction.AreMethodParamsValid(methodParams)) { continue; } this.methodDescriptors.Add(new MethodDescriptor(method, methodParams)); } this.methodDescriptors = this.methodDescriptors.OrderByDescending((methodDescriptor) => { int distanceFromBaseClass = 0; if (methodDescriptor.HasParameters) { Type typeWalker = methodDescriptor.SecondParameterType; while (typeWalker != typeof(EventArgs)) { distanceFromBaseClass++; typeWalker = typeWalker.BaseType; } } return(methodDescriptor.ParameterCount + distanceFromBaseClass); }).ToList(); } }
private static void OnTargetObjectChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { CallMethodAction callMethodAction = (CallMethodAction)sender; callMethodAction.UpdateMethodInfo(); }