This project is read-only.

What would be invloved in creating "Bindable Properties" as below

Topics: C# Language Design
Apr 30, 2014 at 3:25 PM
Currently I have a Base class that looks like
public abstract class ViewModelBase : INotifyPropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;
    protected bool UpdateProperty<T>(ref T currentValue, T newValue, [CallerMemberName] string propertyName = "")
        if (currentValue == null || !currentValue.Equals(newValue))
            currentValue = newValue;
            return true;

        return false;
    protected void RaisePropertyChanged(string propertyName)
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
I would like to have the UpdateProperty method added "automatically" at compile time. So basically instead of adding code like
private ObservableCollection<ProjectRelease> projectReleases = new ObservableCollection<ProjectRelease>();
public ObservableCollection<ProjectRelease> ProjectReleases
    get { return projectReleases; }
        base.UpdateProperty(ref projectReleases, value);
I want to be able to add something like
public ObservableCollection<ProjectRelease> ProjectReleases { get; [Bind(UpdateProperty)] set; }
Anybody have any thoughts on this or easy ways to do it currently with the current language features?
Apr 30, 2014 at 9:47 PM
Olmo started a very interesting thread about implementing metaprogramming with attributes.
You can actually do this sort of thing today with aspect-oriented programming (AOP) tools like PostSharp - they are "IL weavers" and make sure the right code is stitched in after the code is first compiled.
Apr 30, 2014 at 11:42 PM
sure they are, but it would be nice to have that in a language.
Apr 30, 2014 at 11:49 PM
If meta programming gets implemented you won't even need to specify UpdateProperty in your attribute, so it will be even sorter and will enable many other scenarios.

What benefit you think a first class integration will provide?