Skip to content

Commit bd1955d

Browse files
committed
support overridable property
1 parent 954ab78 commit bd1955d

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/ReactiveUI.SourceGenerators/AttributeDefinitions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ internal sealed class ReactiveAttribute : Attribute
133133
/// The AccessModifier of the set property.
134134
/// </value>
135135
public AccessModifier SetModifier { get; init; }
136+
public bool Overridable { get; init; } = false;
136137
}
137138
#nullable restore
138139
#pragma warning restore

src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator{FromField}.Execute.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public sealed partial class ObservableAsPropertyGenerator
5555
// Get the can PropertyName member, if any
5656
attributeData.TryGetNamedArgument("ReadOnly", out bool? isReadonly);
5757

58+
// Get Overridable value from the attribute
59+
attributeData.TryGetNamedArgument("Overridable", out bool? overridableArgument);
60+
var overridable = overridableArgument == false ? "virtual" : string.Empty;
61+
5862
token.ThrowIfCancellationRequested();
5963

6064
// Get the property type and name
@@ -198,7 +202,8 @@ public sealed partial class ObservableAsPropertyGenerator
198202
isReferenceTypeOrUnconstraindTypeParameter,
199203
includeMemberNotNullOnSetAccessor,
200204
forwardedPropertyAttributes,
201-
isReadonly == false ? string.Empty : "readonly"),
205+
isReadonly == false ? string.Empty : "readonly",
206+
overridable),
202207
builder.ToImmutable());
203208
}
204209

src/ReactiveUI.SourceGenerators/Reactive/Models/PropertyInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ internal sealed record PropertyInfo(
2424
bool IsReferenceTypeOrUnconstrainedTypeParameter,
2525
bool IncludeMemberNotNullOnSetAccessor,
2626
EquatableArray<string> ForwardedAttributes,
27-
string AccessModifier);
27+
string AccessModifier,
28+
string Overridable);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public sealed partial class ReactiveGenerator
7575
_ => "public",
7676
};
7777

78+
// Get Overridable value from the attribute
79+
attributeData.TryGetNamedArgument("Overridable", out bool? overridableArgument);
80+
var overridable = overridableArgument == true ? "virtual" : string.Empty;
81+
7882
token.ThrowIfCancellationRequested();
7983

8084
// Get the property type and name
@@ -214,7 +218,8 @@ public sealed partial class ReactiveGenerator
214218
isReferenceTypeOrUnconstraindTypeParameter,
215219
includeMemberNotNullOnSetAccessor,
216220
forwardedAttributesString,
217-
accessModifier),
221+
accessModifier,
222+
overridable),
218223
builder.ToImmutable());
219224
}
220225

@@ -282,7 +287,7 @@ private static string GetPropertySyntax(PropertyInfo propertyInfo)
282287
$$"""
283288
/// <inheritdoc cref="{{propertyInfo.FieldName}}"/>
284289
{{propertyAttributes}}
285-
{{propertyInfo.TargetVisibility}} {{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}}
290+
{{propertyInfo.TargetVisibility}} {{propertyInfo.Overridable}} {{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}}
286291
{
287292
get => {{propertyInfo.FieldName}};
288293
[global::System.Diagnostics.CodeAnalysis.MemberNotNull("{{propertyInfo.FieldName}}")]
@@ -295,7 +300,7 @@ private static string GetPropertySyntax(PropertyInfo propertyInfo)
295300
$$"""
296301
/// <inheritdoc cref="{{propertyInfo.FieldName}}"/>
297302
{{propertyAttributes}}
298-
{{propertyInfo.TargetVisibility}} {{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}} { get => {{propertyInfo.FieldName}}; {{setModifier}}set => this.RaiseAndSetIfChanged(ref {{propertyInfo.FieldName}}, value); }
303+
{{propertyInfo.TargetVisibility}} {{propertyInfo.Overridable}} {{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}} { get => {{propertyInfo.FieldName}}; {{setModifier}}set => this.RaiseAndSetIfChanged(ref {{propertyInfo.FieldName}}, value); }
299304
""";
300305
}
301306

0 commit comments

Comments
 (0)