|
3 | 3 | // The .NET Foundation licenses this file to you under the MIT license.
|
4 | 4 | // See the LICENSE file in the project root for full license information.
|
5 | 5 |
|
6 |
| -using System.Drawing; |
7 |
| -using System.Reactive; |
8 |
| -using System.Reactive.Linq; |
9 |
| -using System.Runtime.Serialization; |
10 |
| -using System.Text.Json.Serialization; |
11 |
| -using ReactiveUI; |
12 |
| -using ReactiveUI.SourceGenerators; |
13 |
| - |
14 | 6 | namespace SGReactiveUI.SourceGenerators.Test;
|
15 | 7 |
|
16 |
| -#pragma warning disable SA1402 // File may only contain a single type |
17 |
| -#pragma warning disable SA1649 // File name should match first type name |
18 |
| -#pragma warning disable CA1822 // Mark members as static |
19 |
| - |
20 | 8 | /// <summary>
|
21 | 9 | /// EntryPoint.
|
22 | 10 | /// </summary>
|
23 |
| -public static class EntryPoint |
| 11 | +public static class Program |
24 | 12 | {
|
25 | 13 | /// <summary>
|
26 | 14 | /// Defines the entry point of the application.
|
27 | 15 | /// </summary>
|
28 | 16 | public static void Main() => _ = TestViewModel.Instance;
|
29 | 17 | }
|
30 |
| - |
31 |
| -/// <summary> |
32 |
| -/// TestClass. |
33 |
| -/// </summary> |
34 |
| -[DataContract] |
35 |
| -public partial class TestViewModel : ReactiveObject |
36 |
| -{ |
37 |
| - [JsonInclude] |
38 |
| - [DataMember] |
39 |
| - [ObservableAsProperty] |
40 |
| - private double _test2Property; |
41 |
| - |
42 |
| - [JsonInclude] |
43 |
| - [Reactive] |
44 |
| - [DataMember] |
45 |
| - private int _test1Property; |
46 |
| - |
47 |
| - /// <summary> |
48 |
| - /// Initializes a new instance of the <see cref="TestViewModel"/> class. |
49 |
| - /// </summary> |
50 |
| - public TestViewModel() |
51 |
| - { |
52 |
| - InitializeCommands(); |
53 |
| - |
54 |
| - Console.Out.WriteLine(Test1Command); |
55 |
| - Console.Out.WriteLine(Test2Command); |
56 |
| - Console.Out.WriteLine(Test3AsyncCommand); |
57 |
| - Console.Out.WriteLine(Test4AsyncCommand); |
58 |
| - Console.Out.WriteLine(Test5StringToIntCommand); |
59 |
| - Console.Out.WriteLine(Test6ArgOnlyCommand); |
60 |
| - Console.Out.WriteLine(Test7ObservableCommand); |
61 |
| - Console.Out.WriteLine(Test8ObservableCommand); |
62 |
| - Console.Out.WriteLine(Test9AsyncCommand); |
63 |
| - Console.Out.WriteLine(Test10AsyncCommand); |
64 |
| - Test1Command?.Execute().Subscribe(); |
65 |
| - Test2Command?.Execute().Subscribe(r => Console.Out.WriteLine(r)); |
66 |
| - Test3AsyncCommand?.Execute().Subscribe(); |
67 |
| - Test4AsyncCommand?.Execute().Subscribe(r => Console.Out.WriteLine(r)); |
68 |
| - Test5StringToIntCommand?.Execute("100").Subscribe(Console.Out.WriteLine); |
69 |
| - Test6ArgOnlyCommand?.Execute("Hello World").Subscribe(); |
70 |
| - Test7ObservableCommand?.Execute().Subscribe(); |
71 |
| - |
72 |
| - _test2PropertyHelper = Test8ObservableCommand!.ToProperty(this, x => x.Test2Property); |
73 |
| - |
74 |
| - Test8ObservableCommand?.Execute(100).Subscribe(Console.Out.WriteLine); |
75 |
| - Console.Out.WriteLine($"Test2Property Value: {Test2}"); |
76 |
| - Console.Out.WriteLine($"Test2Property underlying Value: {_test2Property}"); |
77 |
| - |
78 |
| - Test9AsyncCommand?.ThrownExceptions.Subscribe(Console.Out.WriteLine); |
79 |
| - var cancel = Test9AsyncCommand?.Execute().Subscribe(); |
80 |
| - Task.Delay(1000).Wait(); |
81 |
| - cancel?.Dispose(); |
82 |
| - |
83 |
| - Test10AsyncCommand?.Execute(200).Subscribe(r => Console.Out.WriteLine(r)); |
84 |
| - |
85 |
| - Console.ReadLine(); |
86 |
| - } |
87 |
| - |
88 |
| - /// <summary> |
89 |
| - /// Gets the instance. |
90 |
| - /// </summary> |
91 |
| - /// <value> |
92 |
| - /// The instance. |
93 |
| - /// </value> |
94 |
| - public static TestViewModel Instance { get; } = new(); |
95 |
| - |
96 |
| - /// <summary> |
97 |
| - /// Gets the can execute test1. |
98 |
| - /// </summary> |
99 |
| - /// <value> |
100 |
| - /// The can execute test1. |
101 |
| - /// </value> |
102 |
| - public IObservable<bool> CanExecuteTest1 => Observable.Return(true); |
103 |
| - |
104 |
| - /// <summary> |
105 |
| - /// Test1s this instance. |
106 |
| - /// </summary> |
107 |
| - [ReactiveCommand(CanExecute = nameof(CanExecuteTest1))] |
108 |
| - [property: JsonInclude] |
109 |
| - private void Test1() => Console.Out.WriteLine("Test1"); |
110 |
| - |
111 |
| - /// <summary> |
112 |
| - /// Test2s this instance. |
113 |
| - /// </summary> |
114 |
| - /// <returns>Rectangle.</returns> |
115 |
| - [ReactiveCommand] |
116 |
| - private Rectangle Test2() => default; |
117 |
| - |
118 |
| - /// <summary> |
119 |
| - /// Test3s the asynchronous. |
120 |
| - /// </summary> |
121 |
| - /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> |
122 |
| - [ReactiveCommand] |
123 |
| - private async Task Test3Async() => await Task.Delay(0); |
124 |
| - |
125 |
| - /// <summary> |
126 |
| - /// Test4s the asynchronous. |
127 |
| - /// </summary> |
128 |
| - /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> |
129 |
| - [ReactiveCommand] |
130 |
| - private async Task<Rectangle> Test4Async() => await Task.FromResult(new Rectangle(0, 0, 100, 100)); |
131 |
| - |
132 |
| - /// <summary> |
133 |
| - /// Test5s the string to int. |
134 |
| - /// </summary> |
135 |
| - /// <param name="str">The string.</param> |
136 |
| - /// <returns>int.</returns> |
137 |
| - [ReactiveCommand] |
138 |
| - private int Test5StringToInt(string str) => int.Parse(str); |
139 |
| - |
140 |
| - /// <summary> |
141 |
| - /// Test6s the argument only. |
142 |
| - /// </summary> |
143 |
| - /// <param name="str">The string.</param> |
144 |
| - [ReactiveCommand] |
145 |
| - private void Test6ArgOnly(string str) => Console.Out.WriteLine($">>> {str}"); |
146 |
| - |
147 |
| - /// <summary> |
148 |
| - /// Test7s the observable. |
149 |
| - /// </summary> |
150 |
| - /// <returns>An Observable of Unit.</returns> |
151 |
| - [ReactiveCommand] |
152 |
| - private IObservable<Unit> Test7Observable() => Observable.Return(Unit.Default); |
153 |
| - |
154 |
| - /// <summary> |
155 |
| - /// Test8s the observable. |
156 |
| - /// </summary> |
157 |
| - /// <param name="i">The i.</param> |
158 |
| - /// <returns>An Observable of int.</returns> |
159 |
| - [ReactiveCommand] |
160 |
| - private IObservable<double> Test8Observable(int i) => Observable.Return(i + 10.0); |
161 |
| - |
162 |
| - [ReactiveCommand] |
163 |
| - private async Task Test9Async(CancellationToken ct) => await Task.Delay(2000, ct); |
164 |
| - |
165 |
| - [ReactiveCommand] |
166 |
| - private async Task<Rectangle> Test10Async(int size, CancellationToken ct) => await Task.FromResult(new Rectangle(0, 0, size, size)); |
167 |
| -} |
168 |
| - |
169 |
| -#pragma warning restore CA1822 // Mark members as static |
170 |
| -#pragma warning restore SA1649 // File name should match first type name |
171 |
| -#pragma warning restore SA1402 // File may only contain a single type |
0 commit comments