LibraStack / UnityMvvmToolkit

Brings data-binding to your Unity project
MIT License
469 stars 27 forks source link

ObservableAttribue support for private properties #15

Closed Hellfim closed 1 year ago

Hellfim commented 1 year ago

Hi! I would like to have an ObservableAttribute support for private properties.

Currently it only supports private fields.

In cases you don't want to expose your private/protected properties, but still want to make them available just to the View having ObservableAttribute on such properties would be a good thing

ChebanovDD commented 1 year ago

Hi there,

In the next release, it will be possible to apply ObservableAttribute to fields and properties. And the binding logic will be unified for Properties and Commands.

public class MyViewModel : IBindingContext
{
    [Observable("Count")]
    private readonly IProperty<int> _amount;

    [Observable]
    private readonly ICommand _myCommand;

    [Observable]
    protected IProperty<string> Name { get; }

    [Observable("PreviousPropertyName")]
    public IReadOnlyProperty<string> NewPropertyName { get; }
}