public ReversibleInstancePropertyEdit(ReversibleInstancePropertySetter <TProperty> setter, TProperty oldValue, TProperty newValue) { this.setter = setter; this.oldValue = oldValue; this.newValue = newValue; }
/// <summary> /// Set a property /field value, if a transaction is active it is transacted and undoable, if the owner supports INotifyPropertyChanged, the required events will be raised /// </summary> /// <typeparam name = "TProperty"></typeparam> /// The property type to be set /// <param name = "field"></param> /// The field to be set /// <param name = "newValue"></param> /// The value to set the field to /// <param name = "setter"></param> /// The function to set and unset the field /// <param name = "notifyPropertyName"></param> /// A list of property names of the owner to raise notification on internal static void SetModelValue <TProperty>(IPersistIfcEntity target, ref TProperty field, TProperty newValue, ReversibleInstancePropertySetter <TProperty> setter, string notifyPropertyName) { //The object must support Property Change Notification so notify ISupportChangeNotification iPropChanged = target as ISupportChangeNotification; if (iPropChanged != null) { Transaction.AddPropertyChange(setter, field, newValue); #if SupportActivation target.Activate(true); #endif iPropChanged.NotifyPropertyChanging(notifyPropertyName); field = newValue; iPropChanged.NotifyPropertyChanged(notifyPropertyName); } else { throw new Exception( string.Format( "Request to Notify Property Changes on type {0} that does not support ISupportChangeNotification", target.GetType().Name)); } }
/// <summary> /// Adds a reversible property change to the current transaction (if any). /// </summary> /// <param name = "setter">A instance method (delegate) that sets the property of to a given value</param> /// <typeparam name = "TProperty">Type of property</typeparam> /// <param name = "oldValue">The present value of the property</param> /// <param name = "newValue">The new value to be assigned to the property</param> public static void AddPropertyChange <TProperty>(ReversibleInstancePropertySetter <TProperty> setter, TProperty oldValue, TProperty newValue) { Transaction txn = _current; if (txn != null) { txn.AddEdit(new ReversibleInstancePropertyEdit <TProperty>(setter, oldValue, newValue)); } }