// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset.WixBA
{
using System;
using System.ComponentModel;
using System.Diagnostics;
///
/// It provides support for property change notifications.
///
public abstract class PropertyNotifyBase : INotifyPropertyChanged
{
///
/// Initializes a new instance of the class.
///
protected PropertyNotifyBase()
{
}
///
/// Raised when a property on this object has a new value.
///
public event PropertyChangedEventHandler PropertyChanged;
///
/// Warns the developer if this object does not have a public property with the
/// specified name. This method does not exist in a Release build.
///
/// Property name to verify.
[Conditional("DEBUG")]
[DebuggerStepThrough]
public void VerifyPropertyName(string propertyName)
{
// Verify that the property name matches a real, public, instance property
// on this object.
if (null == TypeDescriptor.GetProperties(this)[propertyName])
{
Debug.Fail(String.Concat("Invalid property name: ", propertyName));
}
}
///
/// Raises this object's PropertyChanged event.
///
/// The property that has a new value.
protected virtual void OnPropertyChanged(string propertyName)
{
this.VerifyPropertyName(propertyName);
PropertyChangedEventHandler handler = this.PropertyChanged;
if (null != handler)
{
PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
}
}