lundi 4 mars 2019

How can I implement a custom CallerMemberName attribute in C#?

I would like to implement a custom [CallerMemberName] attribute using reflections. How can I get caller member name?

    public string Name
    {
        get => _name;
        set
        {
            if (value == _name)
                return;
            _name = value;
            OnPropertyChanged(this);
        }
    }

    private void OnPropertyChanged(object sender, [CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(sender, new PropertyChangedEventArgs(propertyName));
    }





Aucun commentaire:

Enregistrer un commentaire