using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Security.Permissions; using System.Text; using System.Threading; using System.Web; using BrainTechLLC.ThreadSafeObjects; namespace BrainTechLLC { /// <summary> /// A collection of sequential changes to a single property on a uniquely identified business object / class /// </summary> public class PropertyChangeCollection<T> where T : new() { /// <summary> /// Stores the original property value. Used when CancelUpdate is called to revert properties (quickly) back to their original values. /// </summary> public object _originalValue; public string _propertyName; public ThreadSafeList<PropertyChangeNotificationArgs> _propertyChanges = new ThreadSafeList<PropertyChangeNotificationArgs>(); public PropertyDescriptor _propertyDescriptor = null; public object FinalValue { get { return _propertyChanges.GetLastItemInList(); } } public void Reset() { _propertyChanges.Clear(); _originalValue = null; } /// <summary> /// Records a property change /// </summary> public void RecordChange(PropertyChangeNotificationArgs changeArgs) { if (_originalValue == null) { Interlocked.CompareExchange<object>(ref _originalValue, changeArgs._previousValue, null); _propertyDescriptor = TypeDescriptor.GetProperties(typeof(T))[changeArgs.PropertyName]; _propertyName = changeArgs.PropertyName; } _propertyChanges.Add(changeArgs); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)