Skip to content

Commit 9c1feac

Browse files
Feature overridable Inheritance property (#123)
* support overridable property * Update to use enum, fix tests --------- Co-authored-by: Chris Pulman <[email protected]>
1 parent 954ab78 commit 9c1feac

15 files changed

+239
-20
lines changed

src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperiesWithAttributes#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,16 @@ internal enum AccessModifier
2121
InternalProtected,
2222
PrivateProtected,
2323
}
24+
25+
/// <summary>
26+
/// InheritanceModifier.
27+
/// </summary>
28+
internal enum InheritanceModifier
29+
{
30+
None,
31+
Virtual,
32+
Override,
33+
New,
34+
}
2435
#nullable restore
2536
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperiesWithAttributes#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ internal sealed class ReactiveAttribute : Attribute
2525
/// The AccessModifier of the set property.
2626
/// </value>
2727
public AccessModifier SetModifier { get; init; }
28+
29+
/// <summary>
30+
/// Gets the InheritanceModifier of the property.
31+
/// </sumary>
32+
public InheritanceModifier Inheritance { get; init; }
2833
}
2934
#nullable restore
3035
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,16 @@ internal enum AccessModifier
2121
InternalProtected,
2222
PrivateProtected,
2323
}
24+
25+
/// <summary>
26+
/// InheritanceModifier.
27+
/// </summary>
28+
internal enum InheritanceModifier
29+
{
30+
None,
31+
Virtual,
32+
Override,
33+
New,
34+
}
2435
#nullable restore
2536
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactiveProperties#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ internal sealed class ReactiveAttribute : Attribute
2525
/// The AccessModifier of the set property.
2626
/// </value>
2727
public AccessModifier SetModifier { get; init; }
28+
29+
/// <summary>
30+
/// Gets the InheritanceModifier of the property.
31+
/// </sumary>
32+
public InheritanceModifier Inheritance { get; init; }
2833
}
2934
#nullable restore
3035
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.AccessModifier.g.verified.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,16 @@ internal enum AccessModifier
2121
InternalProtected,
2222
PrivateProtected,
2323
}
24+
25+
/// <summary>
26+
/// InheritanceModifier.
27+
/// </summary>
28+
internal enum InheritanceModifier
29+
{
30+
None,
31+
Virtual,
32+
Override,
33+
New,
34+
}
2435
#nullable restore
2536
#pragma warning restore

src/ReactiveUI.SourceGenerator.Tests/REACTIVE/ReactiveGeneratorTests.FromReactivePropertiesWithAccess#ReactiveUI.SourceGenerators.ReactiveAttribute.g.verified.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ internal sealed class ReactiveAttribute : Attribute
2525
/// The AccessModifier of the set property.
2626
/// </value>
2727
public AccessModifier SetModifier { get; init; }
28+
29+
/// <summary>
30+
/// Gets the InheritanceModifier of the property.
31+
/// </sumary>
32+
public InheritanceModifier Inheritance { get; init; }
2833
}
2934
#nullable restore
3035
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//HintName: ReactiveUI.SourceGenerators.AccessModifier.g.cs
2+
// Copyright (c) 2024 .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+
/// AccessModifier.
14+
/// </summary>
15+
internal enum AccessModifier
16+
{
17+
Public,
18+
Protected,
19+
Internal,
20+
Private,
21+
InternalProtected,
22+
PrivateProtected,
23+
}
24+
25+
/// <summary>
26+
/// InheritanceModifier.
27+
/// </summary>
28+
internal enum InheritanceModifier
29+
{
30+
None,
31+
Virtual,
32+
Override,
33+
New,
34+
}
35+
#nullable restore
36+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//HintName: ReactiveUI.SourceGenerators.ReactiveAttribute.g.cs
2+
// Copyright (c) 2024 .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+
using System;
8+
9+
// <auto-generated/>
10+
#pragma warning disable
11+
#nullable enable
12+
namespace ReactiveUI.SourceGenerators;
13+
14+
/// <summary>
15+
/// ReactiveAttribute.
16+
/// </summary>
17+
/// <seealso cref="Attribute" />
18+
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
19+
internal sealed class ReactiveAttribute : Attribute
20+
{
21+
/// <summary>
22+
/// Gets the AccessModifier of the set property.
23+
/// </summary>
24+
/// <value>
25+
/// The AccessModifier of the set property.
26+
/// </value>
27+
public AccessModifier SetModifier { get; init; }
28+
29+
/// <summary>
30+
/// Gets the InheritanceModifier of the property.
31+
/// </sumary>
32+
public InheritanceModifier Inheritance { get; init; }
33+
}
34+
#nullable restore
35+
#pragma warning restore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//HintName: TestVM.Properties.g.cs
2+
// <auto-generated/>
3+
using ReactiveUI;
4+
5+
#pragma warning disable
6+
#nullable enable
7+
8+
namespace TestNs
9+
{
10+
/// <summary>
11+
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
12+
/// </summary>
13+
public partial class TestVM
14+
{
15+
/// <inheritdoc cref="_name"/>
16+
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
17+
[global::System.Runtime.Serialization.DataMemberAttribute()]
18+
[global::System.Text.Json.Serialization.JsonIncludeAttribute()]
19+
public string? Name { get => _name; set => this.RaiseAndSetIfChanged(ref _name, value); }
20+
}
21+
}
22+
#nullable restore
23+
#pragma warning restore

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,39 @@ public partial class TestVM : ReactiveObject
109109
return VerifyGenerator(driver);
110110
}
111111

112+
/// <summary>
113+
/// Froms the reactive properties with attributes and access and inheritance.
114+
/// </summary>
115+
/// <returns>A task to monitor the async.</returns>
116+
[Fact]
117+
public Task FromReactivePropertiesWithAttributesAccessAndInheritance()
118+
{
119+
// Arrange: Setup the source code that matches the generator input expectations.
120+
const string sourceCode = @"
121+
using System;
122+
using System.Runtime.Serialization;
123+
using System.Text.Json.Serialization;
124+
using ReactiveUI;
125+
using ReactiveUI.SourceGenerators;
126+
using System.Reactive.Linq;
127+
128+
namespace TestNs;
129+
130+
public partial class TestVM : ReactiveObject
131+
{
132+
[property: JsonInclude]
133+
[DataMember]
134+
[Reactive(Inheritance = InheritanceModifier.Virtual, SetModifier = AccessModifier.Protected)]
135+
private string? _name;
136+
}
137+
";
138+
139+
// Act: Initialize the helper and run the generator.
140+
var driver = TestHelper.TestPass(sourceCode);
141+
142+
// Assert: Verify the generated code.
143+
return VerifyGenerator(driver);
144+
}
145+
112146
private SettingsTask VerifyGenerator(GeneratorDriver driver) => Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()).ScrubLinesContaining("[global::System.CodeDom.Compiler.GeneratedCode(\"");
113147
}

0 commit comments

Comments
 (0)