You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi! I would like to request support for C# partial properties in PropertyChanged.SourceGenerator.
Currently [Notify] works by annotating backing fields:
[Notify]
private string theme = "System";
This generates a public Theme property, which is useful for normal INotifyPropertyChanged scenarios.
However, this pattern does not work well with other source generators, especially System.Text.Json source generation for NativeAOT. The generated property is not visible to the System.Text.Json source generator in the same compilation, so the JSON contract cannot easily use the generated property.
generate the property implementation
raise PropertyChanged
keep hooks such as OnThemeChanged(...)
allow attributes such as [JsonPropertyName], [JsonIgnore], etc. to be placed directly on the property
work better with NativeAOT and System.Text.Json source generation
Example use case:
[JsonSerializable(typeof(AppSettings))]
public partial class AppSettingsJsonContext : JsonSerializerContext;
public partial class AppSettings : INotifyPropertyChanged
{
[Notify]
public partial string Theme { get; set; } = "System";
[Notify]
public partial string ThemeColor { get; set; } = "Blue";
}
This would make the public properties part of the original source code, so other source generators can see them.
CommunityToolkit.Mvvm already supports this style, and it would be great to have similar support here without taking a dependency on the full MVVM Toolkit.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I would like to request support for C# partial properties in PropertyChanged.SourceGenerator.
Currently [Notify] works by annotating backing fields:
This generates a public Theme property, which is useful for normal INotifyPropertyChanged scenarios.
However, this pattern does not work well with other source generators, especially System.Text.Json source generation for NativeAOT. The generated property is not visible to the System.Text.Json source generator in the same compilation, so the JSON contract cannot easily use the generated property.
It would be very useful to support a syntax like:
Expected generated behavior:
generate the property implementation
raise PropertyChanged
keep hooks such as OnThemeChanged(...)
allow attributes such as [JsonPropertyName], [JsonIgnore], etc. to be placed directly on the property
work better with NativeAOT and System.Text.Json source generation
Example use case:
This would make the public properties part of the original source code, so other source generators can see them.
CommunityToolkit.Mvvm already supports this style, and it would be great to have similar support here without taking a dependency on the full MVVM Toolkit.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions