/// <summary> /// Assets a business condition, optionally raising the property changed event. /// </summary> /// <param name="columnName">The name of the column for this rule.</param> /// <param name="message">The message to display if this rule is broken.</param> /// <param name="isValid">Whether this rule is valid.</param> /// <param name="raisePropertyChanged">True to raise the property changed event.</param> public void AssertRule(string columnName, string message, bool isValid, bool raisePropertyChanged) { if (_brokenrules == null) { _brokenrules = new BrokenRules(); } if (!isValid) { _brokenrules.RuleBroken(columnName, message); } else { _brokenrules.RuleBroken(columnName, null); } if (raisePropertyChanged) { OnPropertyChanged(columnName); } }
/// <summary> /// Reverses any changes made since the last BeginEdit call. /// </summary> /// <remarks>This method uses reflection to restore the original values from /// the edit store. After cancelling the object is marked clean and the brokenrules /// collection is cleared.</remarks> public void UndoChanges() { if (_editstore == null) { _editstore = new FieldCache(); } // Restore changed values from edit store. Use reflection to write directly // to local fields in implementing class. DisableChangeTracking(); foreach (KeyValuePair <string, FieldInfo> item in _editstore) { // Lookup schema object associated with changed data ColumnAttribute col; if (!Schema.Cols.TryGetValue(item.Key, out col)) { throw new Exception(string.Format("Unable to restore object state - missing column attribute for field {0}", item.Key)); } // use reflection to access field System.Reflection.FieldInfo field = typeof(T).GetField(col.Storage, BindingFlags.NonPublic | BindingFlags.Instance); if (field == null) { throw new Exception(string.Format("Unable to restore object state - storage field not found for field {0}", item.Key)); } // Restore value field.SetValue(this, item.Value.OriginalValue); } // Restore some key state vars. _brokenrules = _preBrokenRules; _isDeleted = _wasDeleted; EnableChangeTracking(); OnUnknownPropertyChanged(); }
/// <summary> /// Returns a deep-copy clone of the BrokenRules list. /// </summary> /// <returns>A deep-copy clone of this object.</returns> public object Clone() { return(BrokenRules.Clone(this)); }