zoukankan      html  css  js  c++  java
  • 菲佣WPF——3(关于NotifyObject重大bug修复)

    之前的NotifyObjec有问题。是多个属性同时对一个Object进行操作。

    新代码如下。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.ComponentModel;
    using System.Linq.Expressions;
    
    namespace WpfApplication4
    {
        public abstract class NotifyObject:INotifyPropertyChanged
        {
            #region << Field >>
            private Dictionary<string, object> cache = new Dictionary<string, object>();
            #endregion
    
            #region << Property >>
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion
    
            #region << Method >>
            public T GET<T>(Expression<Func<T>> express)
            {
                return GetPropertyValue<T>(GetPropertyName<T>(express));
            }
    
            public void SET<T>(Expression<Func<T>> express, object obj)
            {
                SetPropertyValue(GetPropertyName<T>(express), obj);
            }
    
            private string GetPropertyName<T>(Expression<Func<T>> express)
            {
                var memExpress = (MemberExpression)express.Body;
    
                if (memExpress == null)
                    throw new Exception("The expression is valid");
    
                return memExpress.Member.Name;
            }
    
            private T GetPropertyValue<T>(string propertyName)
            {
                if (string.IsNullOrEmpty(propertyName))
                    return default(T);
                else
                {
                    if (cache.ContainsKey(propertyName))
                        return (T)cache[propertyName];
                    else
                        return default(T);
                }
            }
    
            private void SetPropertyValue(string propertyName, object obj)
            {
                if (cache.ContainsKey(propertyName))
                {
                    if (!Object.ReferenceEquals(cache[propertyName], obj))
                    {
                        cache[propertyName] = obj;
                        Notify(propertyName);
                    }
                }
                else
                {
                    cache.Add(propertyName, obj);
                    Notify(propertyName);
                }
            }
    
            private void Notify(string propertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
            #endregion
        }
    }
  • 相关阅读:
    vulcanjs 包类型
    vulcanjs schemas&& collections
    vulcanjs 核心架构概念
    vulcanjs 开源工具方便快速开发react graphql meteor 应用
    ory Oathkeeper Ecosystem
    ory Oathkeeper docker-compose 安装运行
    benthos stream nats 集成试用
    benthos 几个方便的帮助命令
    benthos 通过配置文件配置 stream 说明
    benthos 通过rest api 配置 stream 说明
  • 原文地址:https://www.cnblogs.com/qiurideyun/p/2912772.html
Copyright © 2011-2022 走看看