How to remove Prism boiler plate code

Stesvis 1,041 Reputation points
2021-01-14T16:01:22.733+00:00

In my app I use both Prism and ReactiveUI for different reasons and it's working really well.

For ReactiveUI there is a package that you can use to remove "boiler plate code":
https://www.reactiveui.net/docs/handbook/view-models/boilerplate-code

For example this:

private string name;
public string Name 
{
    get => name;
    set => this.RaiseAndSetIfChanged(ref name, value);
}

Can be replaced by this:

[Reactive]
public string Name { get; set; }

thanks to that [Reactive] attribute.

In Prism we also define properties with a few lines of code:

private string name;
public string Name
{
    get { return name; }
    set { SetProperty(ref name, value); }
}

I was wondering if anybody knows how to make a custom attribute to obtain this result for Prism too, or if there is already something out there:

[Prism]
public string Name { get; set; }

It would be so great to just use an attribute and not have to create private members etc.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.