aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.WixBA/PropertyNotifyBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.WixBA/PropertyNotifyBase.cs')
-rw-r--r--src/WixToolset.WixBA/PropertyNotifyBase.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/WixToolset.WixBA/PropertyNotifyBase.cs b/src/WixToolset.WixBA/PropertyNotifyBase.cs
new file mode 100644
index 00000000..03174306
--- /dev/null
+++ b/src/WixToolset.WixBA/PropertyNotifyBase.cs
@@ -0,0 +1,59 @@
1// 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.
2
3namespace WixToolset.UX
4{
5 using System;
6 using System.ComponentModel;
7 using System.Diagnostics;
8
9 /// <summary>
10 /// It provides support for property change notifications.
11 /// </summary>
12 public abstract class PropertyNotifyBase : INotifyPropertyChanged
13 {
14 /// <summary>
15 /// Initializes a new instance of the <see cref="PropertyNotifyBase"/> class.
16 /// </summary>
17 protected PropertyNotifyBase()
18 {
19 }
20
21 /// <summary>
22 /// Raised when a property on this object has a new value.
23 /// </summary>
24 public event PropertyChangedEventHandler PropertyChanged;
25
26 /// <summary>
27 /// Warns the developer if this object does not have a public property with the
28 /// specified name. This method does not exist in a Release build.
29 /// </summary>
30 /// <param name="propertyName">Property name to verify.</param>
31 [Conditional("DEBUG")]
32 [DebuggerStepThrough]
33 public void VerifyPropertyName(string propertyName)
34 {
35 // Verify that the property name matches a real, public, instance property
36 // on this object.
37 if (null == TypeDescriptor.GetProperties(this)[propertyName])
38 {
39 Debug.Fail(String.Concat("Invalid property name: ", propertyName));
40 }
41 }
42
43 /// <summary>
44 /// Raises this object's PropertyChanged event.
45 /// </summary>
46 /// <param name="propertyName">The property that has a new value.</param>
47 protected virtual void OnPropertyChanged(string propertyName)
48 {
49 this.VerifyPropertyName(propertyName);
50
51 PropertyChangedEventHandler handler = this.PropertyChanged;
52 if (null != handler)
53 {
54 PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
55 handler(this, e);
56 }
57 }
58 }
59}