Firing an event / function on a property? (C#)

后端 未结 8 1475
你的背包
你的背包 2021-02-08 11:46

I am using a class that I cannot edit, it has a property (a boolean) of which it would be nice to be informed when it changes, I can\'t edit the properties get or set as I am im

8条回答
  •  离开以前
    2021-02-08 12:26

    Could you inherit from the class and hide the property? Something like this...

    class MyClass : BaseClass
    {
        // hide base property.
        public new bool MyProperty
        {
            get
            {
                return base.MyProperty;
            }
    
            set
            {
                base.MyProperty = value;
                RaiseMyPropertyChangedEvent();
            }
        }
    }
    

提交回复
热议问题