Repository navigation
Expand file tree
/
Copy pathTestClassOAPH_VM.cs
More file actions
86 lines (70 loc) · 3.97 KB
/
Copy pathTestClassOAPH_VM.cs
File metadata and controls
86 lines (70 loc) · 3.97 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2019-2026 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.
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using ReactiveUI.Reactive;
using ReactiveUI.SourceGenerators;
namespace SGReactiveUI.SourceGenerators.Test;
/// <summary>Read-only properties that follow reactive properties.</summary>
/// <remarks>
/// <c>[ObservableAsProperty]</c> moved to ReactiveUI.Binding, so this sample writes each
/// <see cref="ObservableAsPropertyHelper{T}"/> by hand with ReactiveUI's <c>ToProperty</c>. On ReactiveUI.Binding, mark a
/// <c>partial</c> property <c>[ObservableAsProperty]</c> and the helper field is generated for you.
/// </remarks>
[ExcludeFromCodeCoverage]
public partial class TestClassOAPH_VM : ReactiveObject
{
/// <summary>Backs <see cref="ObservableTestProperty"/>.</summary>
private readonly ObservableAsPropertyHelper<bool> _observableTestPropertyHelper;
/// <summary>Backs <see cref="ObservableTestField"/>.</summary>
private readonly ObservableAsPropertyHelper<bool> _observableTestFieldHelper;
/// <summary>Backs <see cref="Test"/>.</summary>
private readonly ObservableAsPropertyHelper<string?> _testHelper;
/// <summary>Stores the reactive boolean field.</summary>
[Reactive]
private bool _reactiveTestField;
/// <summary>Stores the reactive string value.</summary>
[Reactive]
private string _value = string.Empty;
/// <summary>Stores the nullable test property.</summary>
[Reactive]
private string? _testProperty;
/// <summary>Initializes a new instance of the <see cref="TestClassOAPH_VM"/> class.</summary>
public TestClassOAPH_VM()
{
_observableTestPropertyHelper = CreateObservableTestPropertyHelper();
_observableTestFieldHelper = CreateObservableTestFieldHelper();
_testHelper = CreateTestHelper();
TestProperty = "Test2";
}
/// <summary>Gets a value indicating whether <see cref="ReactiveTestProperty"/> is set.</summary>
public bool ObservableTestProperty => _observableTestPropertyHelper.Value;
/// <summary>Gets a value indicating whether <see cref="ReactiveTestField"/> is set.</summary>
public bool ObservableTestField => _observableTestFieldHelper.Value;
/// <summary>
/// Gets or sets a value indicating whether [reactive test property].
/// </summary>
/// <value>
/// <c>true</c> if [reactive test property]; otherwise, <c>false</c>.
/// </value>
[Reactive]
public partial bool ReactiveTestProperty { get; set; }
/// <summary>Gets the latest <see cref="TestProperty"/>.</summary>
public string? Test => _testHelper.Value;
/// <summary>Creates the helper that projects the reactive property to its observable counterpart.</summary>
/// <returns>The initialized observable property helper.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private ObservableAsPropertyHelper<bool> CreateObservableTestPropertyHelper() =>
this.WhenAnyValue(static x => x.ReactiveTestProperty).ToProperty(this, static x => x.ObservableTestProperty);
/// <summary>Creates the helper that projects the reactive field to its observable counterpart.</summary>
/// <returns>The initialized observable field helper.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private ObservableAsPropertyHelper<bool> CreateObservableTestFieldHelper() =>
this.WhenAnyValue(static x => x.ReactiveTestField).ToProperty(this, static x => x.ObservableTestField);
/// <summary>Creates the helper that projects the test property.</summary>
/// <returns>The initialized test helper.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private ObservableAsPropertyHelper<string?> CreateTestHelper() =>
this.WhenAnyValue(static x => x.TestProperty).ToProperty(this, static x => x.Test);
}