diff --git a/README.md b/README.md index 22a719b..c1f1318 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ This documentation covers using ReactiveUI Source Generators to simplify and enh ReactiveUI Source Generators automatically generate ReactiveUI objects to streamline your code. These Source Generators are designed to work with ReactiveUI V19.5.31+ and support the following features: - `[Reactive]` With field and access modifiers, partial property support (C# 13 Visual Studio Version 17.12.0), partial properties with initializer support (C# preview only) -- `[Reactive(SetModifier = AccessModifier.Protected)]` With field and access modifiers. +- `[Reactive(SetModifier = AccessModifier.Protected)]` With field and access modifiers, (Not Required for partial properties, configure set accessor with the property decalaration). - `[Reactive(Inheritance = InheritanceModifier.Virtual)]` With field and access modifiers. This will generate a virtual property. -- `[Reactive(UseRequired = true)]` With field and access modifiers. This will generate a required property. +- `[Reactive(UseRequired = true)]` With field and access modifiers. This will generate a required property, (Not Required for partial properties, use required keyword for property decalaration). - `[ObservableAsProperty]` With field, method, Observable property and partial property support (C# 13 Visual Studio Version 17.12.0) - `[ObservableAsProperty(ReadOnly = false)]` Removes readonly keyword from the generated helper field - `[ObservableAsProperty(PropertyName = "ReadOnlyPropertyName")]` diff --git a/src/ReactiveUI.SourceGenerators.Execute/InternalTestViewModel.cs b/src/ReactiveUI.SourceGenerators.Execute/InternalTestViewModel.cs index 1d75abd..e6c8a19 100644 --- a/src/ReactiveUI.SourceGenerators.Execute/InternalTestViewModel.cs +++ b/src/ReactiveUI.SourceGenerators.Execute/InternalTestViewModel.cs @@ -13,6 +13,9 @@ internal partial class InternalTestViewModel : ReactiveObject [Reactive] public partial int PublicPartialPropertyTest { get; set; } + [Reactive] + public required partial bool PublicRequiredPartialPropertyTest { get; set; } + [Reactive] public partial int PublicPartialPropertyWithInternalProtectedTest { get; protected internal set; } diff --git a/src/ReactiveUI.SourceGenerators.Roslyn/Reactive/ReactiveGenerator.Execute.cs b/src/ReactiveUI.SourceGenerators.Roslyn/Reactive/ReactiveGenerator.Execute.cs index 4b03b9f..e66acf9 100644 --- a/src/ReactiveUI.SourceGenerators.Roslyn/Reactive/ReactiveGenerator.Execute.cs +++ b/src/ReactiveUI.SourceGenerators.Roslyn/Reactive/ReactiveGenerator.Execute.cs @@ -120,8 +120,7 @@ public sealed partial class ReactiveGenerator var inheritance = propertySymbol.IsVirtual ? " virtual" : propertySymbol.IsOverride ? " override" : string.Empty; - attributeData.TryGetNamedArgument("UseRequired", out bool useRequiredArgument); - var useRequired = useRequiredArgument ? "required " : string.Empty; + var useRequired = propertySymbol.IsRequired ? "required " : string.Empty; var typeNameWithNullabilityAnnotations = propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations(); var fieldName = propertySymbol.GetGeneratedFieldName(); @@ -410,7 +409,7 @@ private static string GetPropertySyntax(PropertyInfo propertyInfo) {{fieldSyntax}} /// {{propertyAttributes}} - {{accessModifier}}{{propertyInfo.Inheritance}} {{partialModifier}}{{propertyInfo.UseRequired}}{{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}} { get => {{getFieldName}}; {{setAccessModifier}} => this.RaiseAndSetIfChanged(ref {{setFieldName}}, value); } + {{accessModifier}}{{propertyInfo.Inheritance}} {{propertyInfo.UseRequired}}{{partialModifier}}{{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}} { get => {{getFieldName}}; {{setAccessModifier}} => this.RaiseAndSetIfChanged(ref {{setFieldName}}, value); } """; } }