Permalink
Browse files

Added HasChanged. Closes #8.

  • Loading branch information...
1 parent 3898b16 commit 94212b59acea51ca33665c033d9bedfb194d06f0 @bgrainger bgrainger committed Feb 7, 2010
@@ -0,0 +1,24 @@
+
+using System.ComponentModel;
+
+namespace Logos.Utility.ComponentModel
+{
+ /// <summary>
+ /// Provides helper methods for working with <see cref="INotifyPropertyChanged"/>.
+ /// </summary>
+ public static class NotifyPropertyChangedUtility
+ {
+ /// <summary>
+ /// Returns <c>true</c> if <paramref name="e"/> indicates that the property named by <paramref name="propertyName"/> has changed.
+ /// </summary>
+ /// <param name="e">The <see cref="PropertyChangedEventArgs"/>.</param>
+ /// <param name="propertyName">The property name.</param>
+ /// <returns><c>true</c> if the property named by <paramref name="propertyName"/> has changed; otherwise <c>false</c>.</returns>
+ /// <remarks>See <a href="http://code.logos.com/blog/2008/04/handling_the_propertychanged_event.html">Handling the PropertyChanged event</a>.</remarks>
+ public static bool HasChanged(this PropertyChangedEventArgs e, string propertyName)
+ {
+ string eventPropertyName = e.PropertyName;
+ return string.IsNullOrEmpty(eventPropertyName) || propertyName == eventPropertyName;
+ }
+ }
+}
@@ -50,6 +50,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="ComponentModel\NotifyPropertyChangedUtility.cs" />
<Compile Include="DateTimeUtility.cs" />
<Compile Include="DictionaryUtility.cs" />
<Compile Include="DisposableService.cs" />
@@ -60,6 +60,7 @@
<Compile Include="ExpressionUtilityTests.cs" />
<Compile Include="HashCodeUtilityTests.cs" />
<Compile Include="HttpWebRequestUtilityTests.cs" />
+ <Compile Include="NotifyPropertyChangedUtilityTests.cs" />
<Compile Include="ObjectUtilityTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Salsa20Tests.cs" />
@@ -0,0 +1,20 @@
+
+using System.ComponentModel;
+using Logos.Utility.ComponentModel;
+using NUnit.Framework;
+
+namespace Logos.Utility.Tests
+{
+ [TestFixture]
+ public class NotifyPropertyChangedUtilityTests
+ {
+ [TestCase("prop1", "prop1", true)]
+ [TestCase("prop1", "prop2", false)]
+ [TestCase(null, "prop1", true)]
+ public void HasChanged(string eventPropertyName, string testPropertyName, bool expected)
+ {
+ PropertyChangedEventArgs args = new PropertyChangedEventArgs(eventPropertyName);
+ Assert.That(args.HasChanged(testPropertyName), Is.EqualTo(expected));
+ }
+ }
+}

0 comments on commit 94212b5

Please sign in to comment.