示例#1
0
        public ReflectionDataObserver GetObserver(string key)
        {
            ReflectionDataObserver observer;

            if (!observers.TryGetValue(key, out observer))
            {
                observer = new ReflectionDataObserver(key, type);
                observers.Add(key, observer);
            }
            return(observer);
        }
示例#2
0
        public void SetValue <T>(string key, T value, bool notify = false)
        {
            ReflectionDataObserver observer = GetObserver(key);

            if (observer.fieldInfo != null)
            {
                observer.fieldInfo.SetValue(this, value);
                if (notify)
                {
                    observer.Invoke(this);
                }
                return;
            }

            if (observer.propertyInfo != null)
            {
                observer.propertyInfo.SetValue(this, value);
                if (notify)
                {
                    observer.Invoke(this);
                }
                return;
            }
        }
示例#3
0
        public void AddObserver(string key, Action <DataComponent> onValueChanged)
        {
            ReflectionDataObserver observer = GetObserver(key);

            observer.AddEvent(onValueChanged);
        }