<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Notifying objects</title><link>https://sourceforge.net/p/masamune-1/wiki/Notifying%2520objects/</link><description>Recent changes to Notifying objects</description><atom:link href="https://sourceforge.net/p/masamune-1/wiki/Notifying%20objects/feed" rel="self"/><language>en</language><lastBuildDate>Fri, 05 Jun 2020 15:01:56 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/masamune-1/wiki/Notifying%20objects/feed" rel="self" type="application/rss+xml"/><item><title>Notifying objects modified by Alexey Popov</title><link>https://sourceforge.net/p/masamune-1/wiki/Notifying%2520objects/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -12,7 +12,7 @@

 ### `UpdateLock&amp;lt;t&amp;gt;` struct

-This struct implements the `System.IDisposable` interface, calls the `IUpdatable.BeginUpdate` in it's constructor and the `IUpdatable.EndUpdate` in it's `Dispose` method.
+This struct implements the `System.IDisposable` interface, calls the `IUpdatable.BeginUpdate()` in it's constructor and the `IUpdatable.EndUpdate()` in it's `Dispose()` method.

 Suppose you have a class `MyUpdatable` that implements the `IUpdatable` interface. To bulk update the instance of the class use the following code:

@@ -113,7 +113,7 @@

 The `backingField` is the _reference_ to the field that contains the value of the proerty that has been changed. It's a `ref` parameter because backing fields may be value types that are passed by value. The `newValue` is, obviosely, the new value of the property. The `propertyName` is the name of the property that has been changed. The way this argument is declared allows the developer to ommit it, the compiler will generate the correct value automatically.

-Here is an example of this method (a simplified previos example):
+Here is an example of this method (a simplified previous example):

 ```csharp
 string key;
&amp;lt;/t&amp;gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexey Popov</dc:creator><pubDate>Fri, 05 Jun 2020 15:01:56 -0000</pubDate><guid>https://sourceforge.net356d7c5ceeca59d56bacaf7dc0c0d0008c09f1ca</guid></item><item><title>Notifying objects modified by Alexey Popov</title><link>https://sourceforge.net/p/masamune-1/wiki/Notifying%2520objects/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -45,16 +45,16 @@
 * A protected constructor;
 * `PropertyChanged` event
 * `ShouldRaiseEvents` protected boolean property
-* `VerifyPropertyName` conditional method
-* `BeginUpdate`/`EndUpdate` method pair
-* Two protected methods `OnPropertyChanged`
+* `VerifyPropertyName()` conditional method
+* `BeginUpdate()`/`EndUpdate()` method pair
+* Two protected methods `OnPropertyChanged()`
 * `SetPropertyValue&amp;lt;t&amp;gt;` generic helper method

 Let's review these members.

 ### The constructor

-The constructor just sets the `ShouldRaiseEvents` property to '`true' - a newly created `NotifyingObject` notifies it's subscribers about property changes.
+The constructor just sets the `ShouldRaiseEvents` property to __true__ - a newly created `NotifyingObject` notifies it's subscribers about property changes.

 ### `PropertyChanged`

@@ -66,17 +66,17 @@

 __NB__: At the moment the property is implemented as a simple bit flag. However, it migh be better to use a counter instead to allow nested bulk updates. This change might be introduced in the future but it will be a breaking change.

-### `VerifyPropertyName` method
+### `VerifyPropertyName()` method

 This conditional method checks if the inheriting class has a property with provided name. It may save the developer from typos.

 The method is marked with `[Conditional("DEBUG")]` attribute and gets removed in release builds.

-### `BeginUpdate`/`EndUpdate` methods
+### `BeginUpdate()`/`EndUpdate()` methods

 These two virtual methods implement the `IUpdatable` interface and manipulate the value of the `ShouldRaiseEvents` property.

-### `OnPropertyChanged` overloads
+### `OnPropertyChanged()` overloads

 These two protected overloads raise the `PropertyChanged` event. The one that accepts a property name as a parameter is sealed, the other, that accepts an instance of the `System.ComponentModel.PropertyChangedEventArgs` class, is virtual. If you need to intercept the propety changed events in derived classes, override it but call the base implementation.

@@ -103,7 +103,7 @@

 ```

-### `SetPropertyValue&amp;lt;t&amp;gt;` method
+### `SetPropertyValue&amp;lt;t&amp;gt;()` method

 This helper method has following signature:

@@ -183,7 +183,7 @@

 ## `NotifyingCollection` class

-This class is a base class for collection view models. It inherits from the `NotifyingObject` and implements the `System.Collections.Specialized.INotifyCollectionChanged` interface. In addition to the members of the `NotifyingObject` it defines or overrides the following methods:
+This class is a base class for collections with notifications. It inherits from the `NotifyingObject` and implements the `System.Collections.Specialized.INotifyCollectionChanged` interface. In addition to the members of the `NotifyingObject` it defines or overrides the following methods:

 * A protected constructor
 * `CheckReentrancy()` protected method
@@ -222,3 +222,5 @@
 ### `CheckReadOnly()` method

 This method throws an `InvalidOperationException` if the collection is read-only and the user cannot modify it.
+
+These two classes introduce rather flexible boilerplate code for WPF view models.
&amp;lt;/t&amp;gt;&amp;lt;/t&amp;gt;&amp;lt;/t&amp;gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexey Popov</dc:creator><pubDate>Fri, 05 Jun 2020 14:59:00 -0000</pubDate><guid>https://sourceforge.netc7e7aaee94585c95441ffb7d237d4af69d1cd7af</guid></item><item><title>Notifying objects modified by Alexey Popov</title><link>https://sourceforge.net/p/masamune-1/wiki/Notifying%2520objects/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="notifying-objects-in-masamune"&gt;Notifying objects in Masamune&lt;/h1&gt;
&lt;p&gt;Masamune provides base classes for view models. The base class for simple objects is called &lt;code&gt;NotifyingObject&lt;/code&gt; and the base class for collections is called &lt;code&gt;NotifyingCollection&lt;/code&gt;. These classes provide facilities for property changes notifications and their management throug the &lt;code&gt;IUpdatable&lt;/code&gt; interface.&lt;/p&gt;
&lt;h2 id="iupdatable-interface-and-related-types"&gt;&lt;code&gt;IUpdatable&lt;/code&gt; interface and related types&lt;/h2&gt;
&lt;p&gt;This interface is designed to support bulk updates and declares two methods: &lt;code&gt;BeginUpdate()&lt;/code&gt; and &lt;code&gt;EndUpdate()&lt;/code&gt;. When a type implements it, the first method should stop rising notification events and the second - resume them. Thus the type should support a bit flag signalling if the notifications enabled or not.&lt;/p&gt;
&lt;p&gt;It may be a good idea to send a notification that the object has been completely changed in the &lt;code&gt;EndUpdate()&lt;/code&gt; method implementation.&lt;/p&gt;
&lt;p&gt;To simplify use of the interface Masamune provides two utility types: the &lt;code&gt;UpdateLock&amp;lt;T&amp;gt;&lt;/code&gt; struct and the &lt;code&gt;UpdateLock&lt;/code&gt; class.&lt;/p&gt;
&lt;h3 id="updatelockt-struct"&gt;&lt;code&gt;UpdateLock&amp;lt;T&amp;gt;&lt;/code&gt; struct&lt;/h3&gt;
&lt;p&gt;This struct implements the &lt;code&gt;System.IDisposable&lt;/code&gt; interface, calls the &lt;code&gt;IUpdatable.BeginUpdate&lt;/code&gt; in it's constructor and the &lt;code&gt;IUpdatable.EndUpdate&lt;/code&gt; in it's &lt;code&gt;Dispose&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;Suppose you have a class &lt;code&gt;MyUpdatable&lt;/code&gt; that implements the &lt;code&gt;IUpdatable&lt;/code&gt; interface. To bulk update the instance of the class use the following code:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyUpdatable&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GetMyUpdatable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;using&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UpdateLock&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MyUpdatable&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;UpdateLock&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MyUpdatable&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Update the 'instance'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;h3 id="updatelock-class"&gt;&lt;code&gt;UpdateLock&lt;/code&gt; class&lt;/h3&gt;
&lt;p&gt;This static utility class helps one to simplify the code for bulk updates:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;MyUpdatable&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GetMyUpdatable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;using&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;UpdateLock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Acquire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Update the 'instance'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It uses C# type inference to make the &lt;code&gt;using&lt;/code&gt; statement clearer.&lt;/p&gt;
&lt;h2 id="notifyingobject-class"&gt;&lt;code&gt;NotifyingObject&lt;/code&gt; class&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;NotifyingObject&lt;/code&gt; is an abstract base for classes that support notifications. It implements both &lt;code&gt;System.ComponentModel.INotifyPropertyChanged&lt;/code&gt; and &lt;code&gt;IUpdatable&lt;/code&gt; interfaces and defines following members:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A protected constructor;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PropertyChanged&lt;/code&gt; event&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ShouldRaiseEvents&lt;/code&gt; protected boolean property&lt;/li&gt;
&lt;li&gt;&lt;code&gt;VerifyPropertyName&lt;/code&gt; conditional method&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BeginUpdate&lt;/code&gt;/&lt;code&gt;EndUpdate&lt;/code&gt; method pair&lt;/li&gt;
&lt;li&gt;Two protected methods &lt;code&gt;OnPropertyChanged&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SetPropertyValue&amp;lt;T&amp;gt;&lt;/code&gt; generic helper method&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let's review these members.&lt;/p&gt;
&lt;h3 id="the-constructor"&gt;The constructor&lt;/h3&gt;
&lt;p&gt;The constructor just sets the &lt;code&gt;ShouldRaiseEvents&lt;/code&gt; property to '&lt;code&gt;true' - a newly created&lt;/code&gt;NotifyingObject` notifies it's subscribers about property changes.&lt;/p&gt;
&lt;h3 id="propertychanged"&gt;&lt;code&gt;PropertyChanged&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;This event is supposed to be raised when one or more properties change their values. This is the implementatio of the &lt;code&gt;INotifyPropertyChanged&lt;/code&gt; interface.&lt;/p&gt;
&lt;h3 id="shouldraiseevents-property"&gt;&lt;code&gt;ShouldRaiseEvents&lt;/code&gt; property&lt;/h3&gt;
&lt;p&gt;This protected property allows the inheriting code to enable/disable property change notifications or check if they are enabled. It is a good idea to check the state of this property in inheriting classes that add more events.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NB&lt;/strong&gt;: At the moment the property is implemented as a simple bit flag. However, it migh be better to use a counter instead to allow nested bulk updates. This change might be introduced in the future but it will be a breaking change.&lt;/p&gt;
&lt;h3 id="verifypropertyname-method"&gt;&lt;code&gt;VerifyPropertyName&lt;/code&gt; method&lt;/h3&gt;
&lt;p&gt;This conditional method checks if the inheriting class has a property with provided name. It may save the developer from typos.&lt;/p&gt;
&lt;p&gt;The method is marked with &lt;code&gt;[Conditional("DEBUG")]&lt;/code&gt; attribute and gets removed in release builds.&lt;/p&gt;
&lt;h3 id="beginupdateendupdate-methods"&gt;&lt;code&gt;BeginUpdate&lt;/code&gt;/&lt;code&gt;EndUpdate&lt;/code&gt; methods&lt;/h3&gt;
&lt;p&gt;These two virtual methods implement the &lt;code&gt;IUpdatable&lt;/code&gt; interface and manipulate the value of the &lt;code&gt;ShouldRaiseEvents&lt;/code&gt; property.&lt;/p&gt;
&lt;h3 id="onpropertychanged-overloads"&gt;&lt;code&gt;OnPropertyChanged&lt;/code&gt; overloads&lt;/h3&gt;
&lt;p&gt;These two protected overloads raise the &lt;code&gt;PropertyChanged&lt;/code&gt; event. The one that accepts a property name as a parameter is sealed, the other, that accepts an instance of the &lt;code&gt;System.ComponentModel.PropertyChangedEventArgs&lt;/code&gt; class, is virtual. If you need to intercept the propety changed events in derived classes, override it but call the base implementation.&lt;/p&gt;
&lt;p&gt;Here is an example of these methods use:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Key&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;get&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;set&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;OnPropertyChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Key"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;h3 id="setpropertyvaluet-method"&gt;&lt;code&gt;SetPropertyValue&amp;lt;T&amp;gt;&lt;/code&gt; method&lt;/h3&gt;
&lt;p&gt;This helper method has following signature:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;SetPropertyValue&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;backingField&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CallerMemberName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;propertyName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;backingField&lt;/code&gt; is the &lt;em&gt;reference&lt;/em&gt; to the field that contains the value of the proerty that has been changed. It's a &lt;code&gt;ref&lt;/code&gt; parameter because backing fields may be value types that are passed by value. The &lt;code&gt;newValue&lt;/code&gt; is, obviosely, the new value of the property. The &lt;code&gt;propertyName&lt;/code&gt; is the name of the property that has been changed. The way this argument is declared allows the developer to ommit it, the compiler will generate the correct value automatically.&lt;/p&gt;
&lt;p&gt;Here is an example of this method (a simplified previos example):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Key&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;get&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;set&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;SetPropertyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ref&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;You should stick to use this method. One clear exception would be a property that depends on the value of another property:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;FirstName&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;get&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;set&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;OnPropertyChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"FirstName"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;OnPropertyChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"FullName"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;LastName&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;get&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;set&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;lastName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;OnPropertyChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"LastName"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;OnPropertyChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"FullName"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;FullName&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;get&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;h2 id="notifyingcollection-class"&gt;&lt;code&gt;NotifyingCollection&lt;/code&gt; class&lt;/h2&gt;
&lt;p&gt;This class is a base class for collection view models. It inherits from the &lt;code&gt;NotifyingObject&lt;/code&gt; and implements the &lt;code&gt;System.Collections.Specialized.INotifyCollectionChanged&lt;/code&gt; interface. In addition to the members of the &lt;code&gt;NotifyingObject&lt;/code&gt; it defines or overrides the following methods:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A protected constructor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CheckReentrancy()&lt;/code&gt; protected method&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CollectionChanged&lt;/code&gt; event&lt;/li&gt;
&lt;li&gt;&lt;code&gt;OnCollectionChanged()&lt;/code&gt; protected virtual method&lt;/li&gt;
&lt;li&gt;&lt;code&gt;OnPropertyChanged()&lt;/code&gt; protected overloaded method&lt;/li&gt;
&lt;li&gt;&lt;code&gt;IsReadOnly&lt;/code&gt; abstract property&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CheckReadOnly()&lt;/code&gt; protected method&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let's review these members.&lt;/p&gt;
&lt;h3 id="the-constructor_1"&gt;The constructor&lt;/h3&gt;
&lt;p&gt;The constructor initializes the object. The &lt;code&gt;ShouldRaiseEvents&lt;/code&gt; property is set to &lt;code&gt;true&lt;/code&gt; by the base class constructor.&lt;/p&gt;
&lt;h3 id="checkreentrancy-method"&gt;&lt;code&gt;CheckReentrancy()&lt;/code&gt; method&lt;/h3&gt;
&lt;p&gt;The collection cannot be modified when subscribers handle notifications. You should call the &lt;code&gt;CheckReentrancy()&lt;/code&gt; method in any method that potentially modifies the collection. It throws the &lt;code&gt;System.InvalidOperationException&lt;/code&gt; if the collection sends the notifications.&lt;/p&gt;
&lt;h3 id="collectionchanged"&gt;&lt;code&gt;CollectionChanged&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;This complex event is raised when the collection is changed - items being added or removed. Thorougly read the documentation on this event when implementing your observable collections!&lt;/p&gt;
&lt;h3 id="oncollectionchanged-method"&gt;&lt;code&gt;OnCollectionChanged()&lt;/code&gt; method&lt;/h3&gt;
&lt;p&gt;This method raises the &lt;code&gt;CollectionChanged&lt;/code&gt; event. It sets an internal flag during this.&lt;/p&gt;
&lt;h3 id="onpropertychanged-overloaded-method"&gt;&lt;code&gt;OnPropertyChanged()&lt;/code&gt; overloaded method&lt;/h3&gt;
&lt;p&gt;This method is overloaded to set the internal flag during the &lt;code&gt;PropertyChanged&lt;/code&gt; event.&lt;/p&gt;
&lt;h3 id="isreadonly-property"&gt;&lt;code&gt;IsReadOnly&lt;/code&gt; property&lt;/h3&gt;
&lt;p&gt;This abstract property must be implemented by a derived class. It is checked by the &lt;code&gt;CheckReadOnly()&lt;/code&gt; method.&lt;/p&gt;
&lt;h3 id="checkreadonly-method"&gt;&lt;code&gt;CheckReadOnly()&lt;/code&gt; method&lt;/h3&gt;
&lt;p&gt;This method throws an &lt;code&gt;InvalidOperationException&lt;/code&gt; if the collection is read-only and the user cannot modify it.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexey Popov</dc:creator><pubDate>Fri, 05 Jun 2020 14:46:50 -0000</pubDate><guid>https://sourceforge.netea3cf3394cbe2a6c03bfda6d4c22df0564d092fc</guid></item></channel></rss>