private void UpdateActionTarget(object oldTarget, object newTarget) { MethodInfo targetMethodInfo = null; // If it's being set to the initial value, ignore it // At this point, we're executing the View's InitializeComponent method, and the ActionTarget hasn't yet been assigned // If they've opted to throw if the target is null, then this will cause that exception. // We'll just wait until the ActionTarget is assigned, and we're called again if (newTarget == View.InitialActionTarget) { return; } if (newTarget == null) { // If it's Enable or Disable we don't do anything - CanExecute will handle this if (this.TargetNullBehaviour == ActionUnavailableBehaviour.Throw) { var e = new ActionTargetNullException(String.Format("ActionTarget on element {0} is null (method name is {1})", this.Subject, this.MethodName)); this.logger.Error(e); throw e; } else { this.logger.Info("ActionTarget on element {0} is null (method name is {1}), but NullTarget is not Throw, so carrying on", this.Subject, this.MethodName); } } else { var newTargetType = newTarget.GetType(); try { targetMethodInfo = newTargetType.GetMethod(this.MethodName); if (targetMethodInfo == null) { this.logger.Warn("Unable to find method {0} on {1}", this.MethodName, newTargetType.Name); } else { this.AssertTargetMethodInfo(targetMethodInfo, newTargetType); } } catch (AmbiguousMatchException e) { var ex = new AmbiguousMatchException(String.Format("Ambiguous match for {0} method on {1}", this.MethodName, newTargetType.Name), e); this.logger.Error(ex); throw ex; } } this.TargetMethodInfo = targetMethodInfo; this.OnTargetChanged(oldTarget, newTarget); }
private void UpdateActionTarget(object oldTarget, object newTarget) { MethodInfo targetMethodInfo = null; // If it's being set to the initial value, ignore it // At this point, we're executing the View's InitializeComponent method, and the ActionTarget hasn't yet been assigned // If they've opted to throw if the target is null, then this will cause that exception. // We'll just wait until the ActionTarget is assigned, and we're called again if (newTarget == View.InitialActionTarget) return; if (newTarget == null) { // If it's Enable or Disable we don't do anything - CanExecute will handle this if (this.TargetNullBehaviour == ActionUnavailableBehaviour.Throw) { var e = new ActionTargetNullException(String.Format("ActionTarget on element {0} is null (method name is {1})", this.Subject, this.MethodName)); this.logger.Error(e); throw e; } else { this.logger.Info("ActionTarget on element {0} is null (method name is {1}), but NullTarget is not Throw, so carrying on", this.Subject, this.MethodName); } } else { var newTargetType = newTarget.GetType(); targetMethodInfo = newTargetType.GetMethod(this.MethodName); if (targetMethodInfo == null) this.logger.Warn("Unable to find method {0} on {1}", this.MethodName, newTargetType.Name); else this.AssertTargetMethodInfo(targetMethodInfo, newTargetType); } this.TargetMethodInfo = targetMethodInfo; this.OnTargetChanged(oldTarget, newTarget); }