mrousavy / Jellyfish

🐟 An incredibly lightweight and type safe MVVM library for .NET WPF, Silverlight, Xamarin and UWP
MIT License
21 stars 4 forks source link

Use [Property] Attribute #1

Closed mrousavy closed 6 years ago

mrousavy commented 6 years ago

Use [Property] Attribute (PropertyAttribute.cs) for overriding a property's getter and setter methods instead of having backing fields and using the ObservableObject::Set<T>(ref T t, T value) function.

Before:

private string _username;
public string Username
{
    get => _username;
    set => Set(ref _username, value);
}

After:

[Property]
public string Username { get; set; }

Pro:

Con:

mrousavy commented 6 years ago

Does not really work in .NET, because this approach requires either an assembly weaver (like Fody) or a macro (which has limited functionality in .NET)