Skip to content

Commit 1286d27

Browse files
committed
Add test for ReactiveCommand with access modifier
Introduces a new unit test to verify that the ReactiveCommand source generator correctly handles the AccessModifier property. Also updates generated test assets and clarifies a comment in the generator implementation.
1 parent 780e673 commit 1286d27

6 files changed

+155
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//HintName: ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.cs
2+
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
3+
// Licensed to the .NET Foundation under one or more agreements.
4+
// The .NET Foundation licenses this file to you under the MIT license.
5+
// See the LICENSE file in the project root for full license information.
6+
7+
// <auto-generated/>
8+
#pragma warning disable
9+
#nullable enable
10+
namespace ReactiveUI.SourceGenerators;
11+
12+
/// <summary>
13+
/// ReativeCommandAttribute.
14+
/// </summary>
15+
/// <seealso cref="Attribute" />
16+
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
17+
internal sealed class ReactiveCommandAttribute : global::System.Attribute
18+
{
19+
/// <summary>
20+
/// Gets the can execute method or property.
21+
/// </summary>
22+
/// <value>
23+
/// The name of the CanExecute Observable of bool.
24+
/// </value>
25+
public string? CanExecute { get; init; }
26+
27+
/// <summary>
28+
/// Gets the output scheduler.
29+
/// </summary>
30+
/// <value>
31+
/// The output scheduler.
32+
/// </value>
33+
public string? OutputScheduler { get; init; }
34+
35+
/// <summary>
36+
/// Gets the AccessModifier of the ReactiveCommand property.
37+
/// </summary>
38+
/// <value>
39+
/// The AccessModifier of the property.
40+
/// </value>
41+
public PropertyAccessModifier AccessModifier { get; init; }
42+
}
43+
#nullable restore
44+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//HintName: ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.cs
2+
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
3+
// Licensed to the .NET Foundation under one or more agreements.
4+
// The .NET Foundation licenses this file to you under the MIT license.
5+
// See the LICENSE file in the project root for full license information.
6+
7+
// <auto-generated/>
8+
#pragma warning disable
9+
#nullable enable
10+
namespace ReactiveUI.SourceGenerators;
11+
12+
/// <summary>
13+
/// ReativeCommandAttribute.
14+
/// </summary>
15+
/// <seealso cref="Attribute" />
16+
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
17+
internal sealed class ReactiveCommandAttribute : global::System.Attribute
18+
{
19+
/// <summary>
20+
/// Gets the can execute method or property.
21+
/// </summary>
22+
/// <value>
23+
/// The name of the CanExecute Observable of bool.
24+
/// </value>
25+
public string? CanExecute { get; init; }
26+
27+
/// <summary>
28+
/// Gets the output scheduler.
29+
/// </summary>
30+
/// <value>
31+
/// The output scheduler.
32+
/// </value>
33+
public string? OutputScheduler { get; init; }
34+
35+
/// <summary>
36+
/// Gets the AccessModifier of the ReactiveCommand property.
37+
/// </summary>
38+
/// <value>
39+
/// The AccessModifier of the property.
40+
/// </value>
41+
public PropertyAccessModifier AccessModifier { get; init; }
42+
}
43+
#nullable restore
44+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//HintName: ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.cs
2+
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
3+
// Licensed to the .NET Foundation under one or more agreements.
4+
// The .NET Foundation licenses this file to you under the MIT license.
5+
// See the LICENSE file in the project root for full license information.
6+
7+
// <auto-generated/>
8+
#pragma warning disable
9+
#nullable enable
10+
namespace ReactiveUI.SourceGenerators;
11+
12+
/// <summary>
13+
/// ReativeCommandAttribute.
14+
/// </summary>
15+
/// <seealso cref="Attribute" />
16+
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
17+
internal sealed class ReactiveCommandAttribute : global::System.Attribute
18+
{
19+
/// <summary>
20+
/// Gets the can execute method or property.
21+
/// </summary>
22+
/// <value>
23+
/// The name of the CanExecute Observable of bool.
24+
/// </value>
25+
public string? CanExecute { get; init; }
26+
27+
/// <summary>
28+
/// Gets the output scheduler.
29+
/// </summary>
30+
/// <value>
31+
/// The output scheduler.
32+
/// </value>
33+
public string? OutputScheduler { get; init; }
34+
35+
/// <summary>
36+
/// Gets the AccessModifier of the ReactiveCommand property.
37+
/// </summary>
38+
/// <value>
39+
/// The AccessModifier of the property.
40+
/// </value>
41+
public PropertyAccessModifier AccessModifier { get; init; }
42+
}
43+
#nullable restore
44+
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/UnitTests/ReactiveCMDGeneratorTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,25 @@ public partial class TestInnerClass3 : ReactiveObject
217217
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
218218
return TestHelper.TestPass(sourceCode);
219219
}
220+
221+
/// <summary>
222+
/// Froms the reactive command with access modifier.
223+
/// </summary>
224+
/// <returns>A task to monitor the async.</returns>
225+
[Test]
226+
public Task FromReactiveCommandWithAccessModifier()
227+
{
228+
const string sourceCode = """
229+
using System;
230+
using ReactiveUI;
231+
using ReactiveUI.SourceGenerators;
232+
namespace TestNs;
233+
public partial class TestVM : ReactiveObject
234+
{
235+
[ReactiveCommand(AccessModifier = PropertyAccessModifier.Internal)]
236+
private int Test1() => 10;
237+
}
238+
""";
239+
return TestHelper.TestPass(sourceCode);
240+
}
220241
}

src/ReactiveUI.SourceGenerators.Roslyn/ReactiveCommand/ReactiveCommandGenerator.Execute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public partial class ReactiveCommandGenerator
9191

9292
token.ThrowIfCancellationRequested();
9393

94-
// Get RegistrationType enum value from the attribute
94+
// Get AccessModifier enum value from the attribute
9595
attributeData.TryGetNamedArgument("AccessModifier", out int propertyAccessModifier);
9696
var accessModifier = propertyAccessModifier switch
9797
{

0 commit comments

Comments
 (0)