Implementing INotifyPropertyChanged - does a better way exist?

前端 未结 30 2682
感情败类
感情败类 2020-11-21 05:23

Microsoft should have implemented something snappy for INotifyPropertyChanged, like in the automatic properties, just specify {get; set; notify;} I

30条回答
  •  广开言路
    2020-11-21 05:46

    I'm writing a library that deals with INotifyPropertyChanged, and the main idea is using a dynamic proxy to notify changes.

    the repo is here: CaulyKan/NoMorePropertyChanged

    with this library, you can write:

        public dynamic Test1Binding { get; set; }
        public TestDTO Test1
        {
            get { return (TestDTO)Test1Binding; }
            set { SetBinding(nameof(Test1Binding), value); }
        }
    

    Then make all bindings and modifications go to Test1Binding, which will notify PropertyChange and CollectionChanged automatically no matter how complex TestDTO is.

    it can also handle dependencies.

        [DependsOn("Test1Binding.TestString")]
        public string Test2
        {
            get { return Test1Binding.TestString; }
        }
    

    Please give me some suggestions.

提交回复
热议问题