Skip to content

Commit de20111

Browse files
authored
Add IReactiveObject source generator and tests (#352)
* Add IReactiveObject source generator and tests Introduces the [IReactiveObject] attribute and a new source generator to implement IReactiveObject for classes that cannot inherit from ReactiveObject. Updates documentation, adds generator logic, supporting models, and unit tests to verify generated code. Also updates helper and project files to support the new generator. * Remove ViewModelTypeName from ReactiveObjectInfo Eliminated the ViewModelTypeName property from the ReactiveObjectInfo record and updated the generator logic to reflect this change. This simplifies the model and generator by removing unused or unnecessary data. * Fix typos in documentation and comments Corrected 'reative' to 'reactive' in XML documentation and comments across multiple source generator files. Also fixed a typo in the summary for ReactiveCommandAttribute and clarified some comments in ReactiveObjectGenerator. * Update XML doc for ReactiveObject generator test Clarified the summary comment for the test method to specify it tests the ReactiveObject generator with IReactiveObjectAttribute. * Update summary for ReactiveObjectInfo model Revised the XML summary comment for ReactiveObjectInfo to clarify that it represents information about a generated ReactiveObject (view model), improving documentation accuracy. * Fix typo in ReactiveCommand attribute summary Corrected 'ReativeCommandAttribute' to 'ReactiveCommand Attribute' in the summary comments of multiple generated test files for improved clarity and accuracy.
1 parent 8aedecb commit de20111

File tree

30 files changed

+365
-30
lines changed

30 files changed

+365
-30
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ ReactiveUI Source Generators automatically generate ReactiveUI objects to stream
5151
- `[ViewModelControlHost("YourNameSpace.CustomControl")]`
5252
- `[BindableDerivedList]` Generates a derived list from a ReadOnlyObservableCollection backing field
5353
- `[ReactiveCollection]` Generates property changed notifications on add, remove, new actions on a ObservableCollection backing field
54+
- `[IReactiveObject]` Generates IReactiveObject implementation for classes not able to inherit from ReactiveObject
5455

5556
#### IViewFor Registration generator
5657

@@ -684,6 +685,19 @@ public partial class MyReactiveClass : ReactiveObject
684685
}
685686
```
686687

688+
### ReactiveObject implementation for classes not able to inherit from ReactiveObject
689+
```csharp
690+
using ReactiveUI;
691+
using ReactiveUI.SourceGenerators;
692+
693+
[IReactiveObject]
694+
public partial class MyReactiveClass
695+
{
696+
[Reactive]
697+
private string _myProperty;
698+
}
699+
```
700+
687701
### TODO:
688702
- Add ObservableAsProperty to generate from a IObservable method with parameters.
689703

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveAsyncCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommand#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithAccessModifier#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithNestedClasses#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithNullableTypeAndNullableReturnType#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithOutputScheduler#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

src/ReactiveUI.SourceGenerator.Tests/REACTIVECMD/ReactiveCMDGeneratorTests.FromReactiveCommandWithParameter#ReactiveUI.SourceGenerators.ReactiveCommandAttribute.g.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace ReactiveUI.SourceGenerators;
1111

1212
/// <summary>
13-
/// ReativeCommandAttribute.
13+
/// ReactiveCommand Attribute.
1414
/// </summary>
1515
/// <seealso cref="Attribute" />
1616
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//HintName: ReactiveUI.SourceGenerators.IReactiveObjectAttribute.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+
/// IReactiveObject Attribute.
14+
/// </summary>
15+
/// <seealso cref="System.Attribute" />
16+
[global::System.AttributeUsage(global::System.AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
17+
internal sealed class IReactiveObjectAttribute : global::System.Attribute;
18+
#nullable restore
19+
#pragma warning restore

0 commit comments

Comments
 (0)