Skip to content

Commit 24ce747

Browse files
authored
Fix for required keyword on partial properties (#209)
1 parent 75041ce commit 24ce747

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ public TestViewModel()
238238
[Reactive]
239239
public partial string? PartialPropertyTest { get; set; }
240240

241+
/// <summary>
242+
/// Gets or sets the partial property test.
243+
/// </summary>
244+
/// <value>
245+
/// The partial property test.
246+
/// </value>
247+
[Reactive(UseRequired = true)]
248+
public required partial string? PartialRequiredPropertyTest { get; set; }
249+
241250
/// <summary>
242251
/// Gets the internal test property. Should not prompt to replace with INPC Reactive Property.
243252
/// </summary>

src/ReactiveUI.SourceGenerators.Roslyn/Reactive/ReactiveGenerator.Execute.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public sealed partial class ReactiveGenerator
7272
token.ThrowIfCancellationRequested();
7373

7474
var inheritance = propertySymbol.IsVirtual ? " virtual" : propertySymbol.IsOverride ? " override" : string.Empty;
75-
var useRequired = string.Empty;
75+
76+
attributeData.TryGetNamedArgument("UseRequired", out bool useRequiredArgument);
77+
var useRequired = useRequiredArgument ? "required " : string.Empty;
78+
7679
var typeNameWithNullabilityAnnotations = propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations();
7780
var fieldName = propertySymbol.GetGeneratedFieldName();
7881
var propertyName = propertySymbol.Name;
@@ -326,7 +329,7 @@ private static string GetPropertySyntax(PropertyInfo propertyInfo)
326329
{{fieldSyntax}}
327330
/// <inheritdoc cref="{{fieldName}}"/>
328331
{{propertyAttributes}}
329-
{{propertyInfo.TargetInfo.TargetVisibility}}{{propertyInfo.Inheritance}} {{partialModifier}}{{propertyInfo.UseRequired}}{{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}}
332+
{{propertyInfo.TargetInfo.TargetVisibility}}{{propertyInfo.Inheritance}} {{propertyInfo.UseRequired}}{{partialModifier}}{{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}}
330333
{
331334
get => {{propertyInfo.FieldName}};
332335
[global::System.Diagnostics.CodeAnalysis.MemberNotNull("{{fieldName}}")]

0 commit comments

Comments
 (0)