C# Fody extension to generate RaisePropertyChange notifications for properties and ObservableAsPropertyHelper properties.
Nuget package ReactiveUI.Fody:
Install-Package ReactiveUI.Fody
Currently, you need to add ReactiveUI
to your FodyWeavers.xml manually.
##Description##
Eases the need for boilerplate in your view models when using reactiveui. Typically, in your view models you must declare properties like this:
string _SearchId;
public string SearchId {
get { return _SearchId; }
set { this.RaiseAndSetIfChanged(ref _SearchId, value); }
}
This is tedious since all you'd like to do is declare properties as normal:
[Reactive]public string SearchId { get; set; }
If a property is annotated with the [Reactive]
attribute, the plugin will weave the boilerplate into your output based on the simple auto-property declaration you provide. Similarly, in order to handle observable property helper properties, you must declare them like this:
ObservableAsPropertyHelper<string> _PersonInfo;
public string PersonInfo {
get { return _PersonInfo.Value; }
}
Then elsewhere you'd set it up via:
...
.ToProperty(this, x => x.PersonInfo, out _PersonInfo);
This plugin will instead allow you to declare the property like:
[ObservableAsProperty]public extern string PersonInfo { get; }
It will generate the field and implement the property for you. Because there is no field for you to pass to .ToProperty
, you
should use the provided .ToPropertyEx
extension method provided by this library:
...
.ToPropertyEx(this, x => x.PersonInfo);
This extension will assign the auto-generated field for you rather than relying on the out
parameter.