-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ivan G
committed
Nov 29, 2019
1 parent
d6d6ac0
commit 03dadc3
Showing
6 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# INotifyPropertyChanged Support | ||
|
||
INotifyPropertyChanged is part of .NET Framework and is often ised in situations when you want to monitor changes to a class' property. It is also an essential part of **Xamarin**, **WPF**, **UWP**, and **Windows Forms** data binding systems. | ||
|
||
Config.Net totally supports `INPC` interface out of the box, and all you need to do is derive your interface from `INPC`: | ||
|
||
```csharp | ||
public interface IMyConfiguration : INotifyPropertyChanged | ||
{ | ||
string Name { get; set; } | ||
} | ||
``` | ||
|
||
then build your configuration as usual and subscribe to property changed event: | ||
|
||
```csharp | ||
IMyConfiguration config = new ConfigurationBuilder<IMyConfiguration>() | ||
//... | ||
.Build(); | ||
|
||
config.PropertyChanged += (sender, e) => | ||
{ | ||
Assert.Equal("Name", e.PropertyName); | ||
}; | ||
|
||
config.Name = "test"; //this will trigger PropertyChanged delegate | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Text; | ||
using Config.Net.Stores; | ||
using Xunit; | ||
|
||
namespace Config.Net.Tests | ||
{ | ||
public class NotifyPropertyChangedTest | ||
{ | ||
private INPC _interface; | ||
private DictionaryConfigStore _store; | ||
|
||
public NotifyPropertyChangedTest() | ||
{ | ||
_store = new DictionaryConfigStore(); | ||
|
||
_interface = new ConfigurationBuilder<INPC>() | ||
.UseConfigStore(_store) | ||
.Build(); | ||
} | ||
|
||
[Fact] | ||
public void Change_property_calls_notify() | ||
{ | ||
bool isSet = false; | ||
string nameSet = null; | ||
|
||
_interface.PropertyChanged += (sender, e) => | ||
{ | ||
isSet = true; | ||
nameSet = e.PropertyName; | ||
}; | ||
|
||
_interface.Name = "test"; | ||
Assert.True(isSet); | ||
Assert.Equal("Name", nameSet); | ||
} | ||
|
||
[Fact] | ||
public void Change_aliased_property_calls_notify() | ||
{ | ||
bool isSet = false; | ||
string nameSet = null; | ||
|
||
_interface.PropertyChanged += (sender, e) => | ||
{ | ||
isSet = true; | ||
nameSet = e.PropertyName; | ||
}; | ||
|
||
_interface.AliasedName = "test"; | ||
Assert.True(isSet); | ||
Assert.Equal("Name1", nameSet); | ||
} | ||
} | ||
|
||
public interface INPC : INotifyPropertyChanged | ||
{ | ||
string Name { get; set; } | ||
|
||
[Option(Alias = "Name1")] | ||
string AliasedName { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters