Click here to Skip to main content
15,894,180 members
Articles / Programming Languages / C#

INotifyPropertyChanged and Beyond - Part I

Rate me:
Please Sign up or sign in to vote.
4.80/5 (22 votes)
7 May 2007CPOL4 min read 71K   937   72  
Improving and extending the INotifyPropertyChanged interface
using System;
using System.ComponentModel;

namespace NotifyTest {
	/// <summary>
	/// This class extends <see cref="T:PropertyChangedEventArgs"/> and
	/// allows for storing the old and new values of the changed property.
	/// </summary>
	public class PropertyNotificationEventArgs : PropertyChangedEventArgs {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="PropertyNotificationEventArgs"/> class.
		/// </summary>
		/// <param name="propertyName">
		/// The name of the property that is associated with this
		/// notification.
		/// </param>
		public PropertyNotificationEventArgs(String propertyName)
			: this(propertyName, null, null) {
			// No-op
		}

		/// <summary>
		/// Initializes a new instance of the
		/// <see cref="PropertyNotificationEventArgs"/> class.
		/// </summary>
		/// <param name="propertyName">
		/// The name of the property that is associated with this
		/// notification.
		/// </param>
		/// <param name="oldValue">The old value.</param>
		/// <param name="newValue">The new value.</param>
		public PropertyNotificationEventArgs(String propertyName,
			Object oldValue, Object newValue)
			: base(propertyName) {
			this.oldValue = oldValue;
			this.newValue = newValue;
		}

		#endregion // Constructors

		#region Properties

		/// <summary>
		/// Holds the new value of the property.
		/// </summary>
		private Object newValue;

		/// <summary>
		/// Gets the new value of the property.
		/// </summary>
		/// <value>The new value.</value>
		public Object NewValue {
			get {
				return this.newValue;
			}
		}

		/// <summary>
		/// Holds the old value of the property.
		/// </summary>
		private Object oldValue;

		/// <summary>
		/// Gets the old value of the property.
		/// </summary>
		/// <value>The old value.</value>
		public Object OldValue {
			get {
				return this.oldValue;
			}
		}

		#endregion // Properties
	}
}

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
Chief Technology Officer SQL Farms, Inc.
United States United States
My name is Tom Goff and I have been working as a Software Engineer for over 15 years. Over my career, I have primarily focused on Windows programming with C++ and C#. I have also worked extensively with Microsoft SQL Server over the past 6 years.

Comments and Discussions