protected bool Update <TType, TValue>(object sender, TType targetObject, NDBasePropertyKey <TKey, TType, TValue> property, TValue newValue, bool hasNewValue, Func <TValue, bool> updateCode) where TType : class { var(currentValue, currentProvider) = PropertyRegistar <TKey> .GetValueAndProvider(property, targetObject); var(oldValue, hasOldValue) = GetValue(targetObject, property); return(Update(sender, targetObject, property, newValue, hasNewValue, updateCode, oldValue, hasOldValue, currentProvider, currentValue)); }
public bool SetValue <TType, TValue>(NDBasePropertyKey <TKey, TType, TValue> property, TType changingObject, TValue value) where TType : class { var hasValue = value != null || property.Settigns.HasFlag(NDPropertySettings.SetLocalExplicityNull); return(Update(changingObject, changingObject, property, value, hasValue, (mutatedValue) => { if (mutatedValue == null && !property.Settigns.HasFlag(NDPropertySettings.SetLocalExplicityNull)) { PropertyRegistar <TKey> .Lookup <TType, TValue> .Property.Remove((changingObject, property)); } else { PropertyRegistar <TKey> .Lookup <TType, TValue> .Property[(changingObject, property)] = mutatedValue; } return true; })); }
//protected bool Update<TType, TValue>(object sender, TType targetObject, NDBasePropertyKey<TKey, TType, TValue> property, TValue newValue, bool hasNewValue, TValue oldValue, bool hasOldValue, ValueProvider<TKey> currentProvider, TValue currentValue) // where TType : class //{ // return Update(sender, targetObject, property, newValue, hasNewValue, () => true, oldValue, hasOldValue, currentProvider, currentValue); //} internal bool Update <TType, TValue>(object sender, TType targetObject, NDBasePropertyKey <TKey, TType, TValue> property, TValue newProviderValue, bool hasNewValue, Func <TValue, bool> updateCode, TValue oldProviderValue, bool hasOldValue, ValueProvider <TKey> oldActualProvider, TValue oldActualValue) where TType : class { var otherProviderIndex = PropertyRegistar <TKey> .ProviderOrder[oldActualProvider]; var thisIndex = PropertyRegistar <TKey> .ProviderOrder[this]; if (!property.Settigns.HasFlag(NDPropertySettings.CallOnChangedHandlerOnEquals) && Object.Equals(oldProviderValue, newProviderValue) && hasOldValue == hasNewValue) { return(true); } TValue newActualValue = default; ValueProvider <TKey> newActualProvider = null; if (this == oldActualProvider && !hasNewValue) { // the current value was provided by the changing provider but now it will no longer have a value // we need to find out what the new value will be. bool found = false; foreach (var item in PropertyRegistar <TKey> .ValueProviders) { if (item == this) { continue; } var(providerValue, hasValue) = item.GetValue(targetObject, property); if (hasValue) { found = true; newActualProvider = item; newActualValue = providerValue; break; } } if (!found) { throw new InvalidOperationException("No Value Found"); } } else if (otherProviderIndex >= thisIndex) { newActualProvider = this; newActualValue = newProviderValue; } else { newActualProvider = oldActualProvider; newActualValue = oldActualValue; } // We need to call the actial update after we recived the current old value. Otherwise we could already read the OnChangingArg <TKey, TValue> onChangingArg; if (property as object is NDAttachedPropertyKey <TKey, TType, TValue> attach) { var attachArg = OnChangingArg.Create(targetObject, oldProviderValue, hasOldValue, newProviderValue, hasNewValue, this, oldActualProvider, newActualProvider, oldActualValue, newActualValue, hasNewValue || !this.canDeletionBePrevented); onChangingArg = attachArg; attach.changedMethod(attachArg); } else if (property as object is NDPropertyKey <TKey, TType, TValue> p) { onChangingArg = OnChangingArg.Create(oldProviderValue, hasOldValue, newProviderValue, hasNewValue, this, oldActualProvider, newActualProvider, oldActualValue, newActualValue, hasNewValue || !this.canDeletionBePrevented); p.changedMethod(targetObject)(onChangingArg); } else { throw new NotSupportedException(); } var result = PropertyRegistar <TKey> .ChangeValue(sender, property, targetObject, onChangingArg, updateCode); FireEventHandler(property, targetObject, sender, ChangedEventArgs.Create(targetObject, property, oldProviderValue, newProviderValue)); return(result); }
public virtual void LowerProviderUpdated <TType, TValue>(object sender, TType targetObject, NDBasePropertyKey <TKey, TType, TValue> property, TValue value, ValueProvider <TKey> updatedProvider) where TType : class { }
internal override void Generate <TSourceType, TSourceValue>(TSourceType source, NDBasePropertyKey <TKey, TSourceType, TSourceValue> bindingProperty) => base.Register(this.of);
public StartWritable(NDBasePropertyKey <TKey, TType, TValue> property, TType of) : base(property) { this.of = of; Property = property; }
public static IBindingConfiguratorWritable <TKey, TType, TValue> Of <TKey, TType, TValue>(this NDBasePropertyKey <TKey, TType, TValue> property, TType of) where TType : class { return(new StartWritable <TKey, TType, TValue>(property, of)); }
// public static Binding<TKey, TSourceType, TSourceValue, TTargetType, TTargetValue> Bind<TKey, TSourceType, TSourceValue, TTargetType, TTargetValue>(this TSourceType source, NDProperty.Propertys.NDReadOnlyPropertyKey<TKey, TSourceType, TSourceValue> property) //where TTargetType : class //where TSourceType : class // { // throw new NotImplementedException(); // } public static Binding <TKey, TSourceType, TSourceValue, TTargetType, TTargetValue> Bind <TKey, TSourceType, TSourceValue, TTargetType, TTargetValue>(this NDBasePropertyKey <TKey, TSourceType, TSourceValue> property, TSourceType source, IBindingConfiguration <TKey, TSourceValue, TTargetType, TTargetValue> configuration) where TTargetType : class where TSourceType : class { return(new Binding <TKey, TSourceType, TSourceValue, TTargetType, TTargetValue>(source, property, configuration as IInternalBindingConfiguration <TKey, TSourceValue, TTargetType, TTargetValue>)); }