Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObservableProperty property for Class #310

Open
KannanKrish opened this issue Aug 28, 2023 · 0 comments
Open

ObservableProperty property for Class #310

KannanKrish opened this issue Aug 28, 2023 · 0 comments
Labels

Comments

@KannanKrish
Copy link

Current Usage:

public partial class AddContact : ObservableObject
{
    [ObservableProperty] private Guid id;
    [ObservableProperty] private string firstName;
    [ObservableProperty] private string lastName;
    [ObservableProperty] private Phone phone;
    [ObservableProperty] private DateTime? expiry;
    [ObservableProperty] private ObservableCollection<Phone> extraPhones = new();
    [ObservableProperty] private string image;
    [ObservableProperty] private Group group;
    [ObservableProperty] private string email;
    [ObservableProperty]
    [NotifyPropertyChangedFor(nameof(ShowRingtonePlay))]
    [NotifyPropertyChangedFor(nameof(RingtoneFile))]
    private string ringtone;
    public bool ShowRingtonePlay => !Ringtone.IsNullOrEmpty();
    public string RingtoneFile => Path.GetFileName(Ringtone);
    [ObservableProperty] private ObservableCollection<string> emails = new();
    [ObservableProperty] private Company company;
    [ObservableProperty] private Country country;
    [ObservableProperty] private Relationship relationship;
    [ObservableProperty] private Address address;
    [ObservableProperty] private ObservableCollection<Event> events = new();
    [ObservableProperty] private ObservableCollection<SocialMedia> socials = new();
    [ObservableProperty] private ObservableCollection<Note> notes = new();

    private readonly CountryService countryService;
}

Proposed Feature:

[ObservableProperty] or [AllObservableProperty]
public partial class AddContact : ObservableObject
{
    private Guid id;
    private string firstName;
    private string lastName;
    private Phone phone;
    private DateTime? expiry;
    private ObservableCollection<Phone> extraPhones = new();
    private string image;
    private Group group;
    private string email;
    private ObservableCollection<string> emails = new();
    private Company company;
    private Country country;
    private Relationship relationship;
    private Address address;
    private ObservableCollection<Event> events = new();
    private ObservableCollection<SocialMedia> socials = new();
    private ObservableCollection<Note> notes = new();
    
    [NotifyPropertyChangedFor(nameof(ShowRingtonePlay))]
    [NotifyPropertyChangedFor(nameof(RingtoneFile))]
    private string ringtone;
    
    public bool ShowRingtonePlay => !Ringtone.IsNullOrEmpty();
    public string RingtoneFile => Path.GetFileName(Ringtone);
    
    private readonly CountryService countryService;
}

For much better code.

For automatic code generation, avoid public property and private readonly property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant