protected T GetPropertyValue <T>([CallerMemberName] string callerName = "") where T : IRedType { var propertyInfo = RedReflection.GetPropertyByName(this.GetType(), callerName); return((T)InternalGetPropertyValue(typeof(T), propertyInfo.RedName, propertyInfo.Flags)); }
/* * public event ObjectChangedEventHandler ObjectChanged; * * private readonly Dictionary<string, ObjectChangedEventHandler> _delegateCache = new(); * * * private void AddEventHandler(string redPropertyName) * { * if (!_delegateCache.ContainsKey(redPropertyName)) * { * _delegateCache.Add(redPropertyName, delegate (object sender, ObjectChangedEventArgs args) * { * if (args._callStack.Contains(this)) * { * return; * } * args._callStack.Add(this); * * if (sender != null) * { * ObjectChanged?.Invoke(sender, args); * } * else * { * args.RedName = redPropertyName; * ObjectChanged?.Invoke(this, args); * } * }); * } * * if (_properties[redPropertyName] is IRedNotifyObjectChanged notify) * { * notify.ObjectChanged += _delegateCache[redPropertyName]; * } * } * * private void RemoveEventHandler(string redPropertyName) * { * if (!_delegateCache.ContainsKey(redPropertyName)) * { * return; * } * * if (_properties[redPropertyName] is IRedNotifyObjectChanged notify) * { * notify.ObjectChanged -= _delegateCache[redPropertyName]; * } * } * * private void OnObjectChanged(string redPropertyName, object oldValue, object newValue) * { * if (ObjectChanged != null) * { * var args = new ObjectChangedEventArgs(ObjectChangedType.Modified, redPropertyName, oldValue, newValue); * args._callStack.Add(this); * * ObjectChanged.Invoke(this, args); * } * } */ #endregion private string GetRedName(string propertyName) { var property = RedReflection.GetPropertyByName(this.GetType(), propertyName); return(property?.RedName ?? propertyName); }