Click here to Skip to main content
15,897,371 members
Articles / Programming Languages / C#

Applied Use of LinFu/Cecil and Aspect-Oriented Programming Concepts - A Library

Rate me:
Please Sign up or sign in to vote.
4.88/5 (8 votes)
4 Sep 2008CPOL17 min read 35.3K   160   32  
A library of useful functionality using Aspect-Oriented Programming concepts, and implemented using the LinFu and Cecil.Mono projects/frameworks.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Troppus Software
United States United States
Currently working as a Senior Silverlight Developer with Troppus Software in Superior, CO. I enjoy statistics, programming, new technology, playing the cello, and reading codeproject articles. Smile | :)

Comments and Discussions