Repository navigation
Expand file tree
/
Copy pathBindingChangeExamples.cs
More file actions
50 lines (41 loc) · 1.86 KB
/
Copy pathBindingChangeExamples.cs
File metadata and controls
50 lines (41 loc) · 1.86 KB
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
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
namespace ReactiveUI.Binding.Documentation.Observing;
/// <summary>
/// Shows <see cref="BindingChange"/>, the value a binding reports each time it writes. It holds the value that was
/// written and whether the write went from the view model to the view. It is a read-only record struct, so two changes
/// are equal when both members are equal.
/// </summary>
public static class BindingChangeExamples
{
/// <summary>The title a to-do item is renamed to.</summary>
private const string RenamedTitle = "Renew car registration online";
/// <summary>Compares changes; equal members make equal changes.</summary>
public static void CompareBindingChanges()
{
BindingChange fromViewModel = new(RenamedTitle, true);
BindingChange sameChange = new(RenamedTitle, true);
BindingChange fromView = new(RenamedTitle, false);
Console.WriteLine(fromViewModel == sameChange);
Console.WriteLine(fromViewModel != fromView);
Console.WriteLine(fromViewModel.Equals(sameChange));
Console.WriteLine(fromViewModel.Equals((object)fromView));
Console.WriteLine(fromViewModel.GetHashCode() == sameChange.GetHashCode());
// Output:
// True
// True
// True
// False
// True
}
/// <summary>Prints a change; the text names each member.</summary>
public static void PrintBindingChange()
{
BindingChange change = new(RenamedTitle, true);
string text = change.ToString();
Console.WriteLine($"Change: {text}.");
// Output:
// Change: BindingChange { Value = Renew car registration online, FromViewModel = True }.
}
}