-
Notifications
You must be signed in to change notification settings - Fork 256
/
Copy pathUseAutoNotifyGenerator.cs
39 lines (32 loc) · 1.29 KB
/
UseAutoNotifyGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using AutoNotify;
namespace GeneratedDemo
{
// The view model we'd like to augment
public partial class ExampleViewModel
{
[AutoNotify]
private string _text = "private field text";
[AutoNotify(PropertyName = "Count")]
private int _amount = 5;
}
public static class UseAutoNotifyGenerator
{
public static void Run()
{
ExampleViewModel vm = new ExampleViewModel();
// we didn't explicitly create the 'Text' property, it was generated for us
string text = vm.Text;
Console.WriteLine($"Text = {text}");
// Properties can have differnt names generated based on the PropertyName argument of the attribute
int count = vm.Count;
Console.WriteLine($"Count = {count}");
// the viewmodel will automatically implement INotifyPropertyChanged
vm.PropertyChanged += (o, e) => Console.WriteLine($"Property {e.PropertyName} was changed");
vm.Text = "abc";
vm.Count = 123;
// Try adding fields to the ExampleViewModel class above and tagging them with the [AutoNotify] attribute
// You'll see the matching generated properties visibile in IntelliSense in realtime
}
}
}