// Update the control sentries. private void UpdateError() { if (!this.DesignMode) { _dynValidation.OnGet(); if (_validation && _containerControl != null) { foreach (Control control in AllControls(_containerControl)) { Control thisControl = control; ControlValidater validater; if (_controlSentry.TryGetValue(thisControl, out validater)) { validater.SetError(); } else { // Create a sentry if the control has an error method, or is an error control. string getErrorMethodName; bool hasErrorMethod = _getErrorMethod.TryGetValue(thisControl, out getErrorMethodName); if (hasErrorMethod || thisControl is IErrorControl) { if (!hasErrorMethod) { // Create a control validater with no error method. ControlValidater controlValidater = new ControlValidater( errorProvider, thisControl, delegate() { return(string.Empty); }); _controlSentry[thisControl] = controlValidater; controlValidater.SetError(); } else { // Find the error method. MethodInfo getErrorMethod = _containerControl.GetType().GetMethod( getErrorMethodName, new Type[0]); if (getErrorMethod == null) { errorProvider.SetError(thisControl, string.Format( "The method \"string {0}.{1}()\" was not found.", _containerControl.GetType().FullName, getErrorMethodName)); } else { // Create a control validater. ControlValidater controlValidater = new ControlValidater( errorProvider, thisControl, delegate() { return(getErrorMethod.Invoke(_containerControl, new object[0]).ToString()); }); _controlSentry[thisControl] = controlValidater; controlValidater.SetError(); } } } } } } else { errorProvider.Clear(); } } }
// Update the control sentries. private void UpdateError() { if (!this.DesignMode) { _dynValidation.OnGet(); if (_validation && _containerControl != null) { foreach (Control control in AllControls(_containerControl)) { Control thisControl = control; ControlValidater validater; if (_controlSentry.TryGetValue(thisControl, out validater)) { validater.SetError(); } else { // Create a sentry if the control has an error method, or is an error control. string getErrorMethodName; bool hasErrorMethod = _getErrorMethod.TryGetValue(thisControl, out getErrorMethodName); if (hasErrorMethod || thisControl is IErrorControl) { if (!hasErrorMethod) { // Create a control validater with no error method. ControlValidater controlValidater = new ControlValidater( errorProvider, thisControl, delegate() { return string.Empty; }); _controlSentry[thisControl] = controlValidater; controlValidater.SetError(); } else { // Find the error method. MethodInfo getErrorMethod = _containerControl.GetType().GetMethod( getErrorMethodName, new Type[0]); if (getErrorMethod == null) errorProvider.SetError(thisControl, string.Format( "The method \"string {0}.{1}()\" was not found.", _containerControl.GetType().FullName, getErrorMethodName)); else { // Create a control validater. ControlValidater controlValidater = new ControlValidater( errorProvider, thisControl, delegate() { return getErrorMethod.Invoke(_containerControl, new object[0]).ToString(); }); _controlSentry[thisControl] = controlValidater; controlValidater.SetError(); } } } } } } else { errorProvider.Clear(); } } }