//public static void SetProvider<TType, TValue>(Providers.ValueProvider<TValue> provider, TType targetObject, NDPropertyKey<TType, TValue> property) // where TType : class //{ // if (Lookup<TType, TValue>.ProviderListener.ContainsKey((provider.Manager, property, targetObject))) // { // var oldListener = Lookup<TType, TValue>.ProviderListener[(provider.Manager, property, targetObject)]; // provider.Manager.GetProvider(targetObject, property).ValueWillChange -= (EventHandler<IValueWillChangeEventArgs<TValue>>)(object)oldListener; // } // EventHandler<Providers.IValueWillChangeEventArgs<TValue>> listener = (sender, e) => // { // var (beforeLocalProviders, providersAfterLocal) = GetProviders(property, targetObject); // bool fondInBefore = false; // for (int i = 0; i < beforeLocalProviders.Count; i++) // { // if (beforeLocalProviders[i] == beforeLocalProviders) // { // fondInBefore = true; // break; // No provider with higher precedence has a value // } // if (beforeLocalProviders[i].HasValue) // return; // a Provider with higher precedence has a value // } // if (!fondInBefore) // { // if (HasLocalValue(property, targetObject)) // return; // We have a local set value. That has higher precedence. // for (int i = 0; i < providersAfterLocal.Count; i++) // { // if (providersAfterLocal[i] == beforeLocalProviders) // { // fondInBefore = true; // break; // No provider with higher precedence has a value // } // if (providersAfterLocal[i].HasValue) // return; // a Provider with higher precedence has a value // } // } // var oldValue = GetValue(property, targetObject); // if (Equals(oldValue, e.NewValue)) // return; // No need to inform someone // e.AfterChange += () => // { // FireValueChanged(property, targetObject, provider, oldValue, provider.CurrentValue); // }; // }; // Lookup<TType, TValue>.ProviderListener[(provider.Manager, property, targetObject)] = listener; // provider.ValueWillChange += listener; // provider.Manager.SetProvider(provider, targetObject, property); //} private static void AddParentHandler <TType, TValue>(NDReadOnlyPropertyKey <TKey, TType, TValue> p) where TType : class { AddEventHandler(p, (sender, e) => { var tree = Tree.GetTree(e.ChangedObject); var removedParent = tree.Parent?.Current; var affectedItems = new List <(object affectedObject, object oldValue, bool hasOldValue, IInternalNDProperty <TKey> affectedProperty, Type propertyDefinedOn, ValueProvider <TKey> currentProvider, object currentValue)>(); if (inheritedPropertys.Count != 0) { // Get all affacted decendents Queue <Tree> queue = new Queue <Tree>(); queue.Enqueue(tree); while (queue.Count != 0) { tree = queue.Dequeue(); { foreach (var affectedProperty in inheritedPropertys.Where(x => x.Key.IsAssignableFrom(tree.Current.GetType())).SelectMany(x => x.Value.Select(y => new { Value = y, Key = x.Key }))) { if (InheritanceValueProvider <TKey> .Instance.IsParantChangeInteresting(tree.Current, affectedProperty.Value, affectedProperty.Key, removedParent)) { var(currentValue, currentProvider) = affectedProperty.Value.GetValueAndProvider(tree.Current); var(oldValue, hasOldValue) = affectedProperty.Value.GetProviderValue(tree.Current, InheritanceValueProvider <TKey> .Instance); affectedItems.Add((tree.Current, oldValue, hasOldValue, affectedProperty.Value, affectedProperty.Key, currentProvider, currentValue)); }
private void FireEventHandler <TType, TValue>(NDReadOnlyPropertyKey <TKey, TType, TValue> property, TType obj, object sender, ChangedEventArgs <TKey, TType, TValue> args) where TType : class { var dic = this.listener.GetOrCreateValue(obj); if (!dic.ContainsKey(property)) { return; } var wrapper = dic[property] as EventWrapper <ChangedEventArgs <TKey, TType, TValue> >; wrapper.Fire(sender, args); }
/// <summary> /// Adds an event handler to the specific Property on the Specific object. /// </summary> /// <typeparam name="TValue">The type of the Property</typeparam> /// <typeparam name="TType">The Type of the Object that defines the Property</typeparam> /// <param name="property">The Property whichthe Eventhandler will be watch.</param> /// <param name="obj">The object the Eventhandler will be watch.</param> /// <param name="handler">The handler that will be called if the Property changes.</param> public void AddEventHandler <TType, TValue>(NDReadOnlyPropertyKey <TKey, TType, TValue> property, TType obj, EventHandler <ChangedEventArgs <TKey, TType, TValue> > handler) where TType : class { var dic = this.listener.GetOrCreateValue(obj); if (!dic.ContainsKey(property)) { dic.Add(property, new EventWrapper <ChangedEventArgs <TKey, TType, TValue> >()); } var wrapper = dic[property] as EventWrapper <ChangedEventArgs <TKey, TType, TValue> >; wrapper.Handler += handler; }
/// <summary> /// Removes an event handler from the specific Property on the Specific object. /// </summary> /// <typeparam name="TValue">The type of the Property</typeparam> /// <typeparam name="TType">The Type of the Object that defines the Property</typeparam> /// <param name="property">The Property whichthe Eventhandler will be removed.</param> /// <param name="obj">The object the Eventhandler will be removed.</param> /// <param name="handler">The handler that should no longer be called if the Property changes.</param> public void RemoveEventHandler <TType, TValue>(NDReadOnlyPropertyKey <TKey, TType, TValue> property, TType obj, EventHandler <ChangedEventArgs <TKey, TType, TValue> > handler) where TType : class { var dic = this.listener.GetOrCreateValue(obj); if (!dic.ContainsKey(property)) { return; } var wrapper = dic[property] as EventWrapper <ChangedEventArgs <TKey, TType, TValue> >; wrapper.Handler -= handler; if (wrapper.Count == 0) { dic.Remove(property); } }
public static AttachedHelperReadOnly <TKey, TType, TValue> Create <TKey, TType, TValue>(NDReadOnlyPropertyKey <TKey, TType, TValue> property) where TType : class => new AttachedHelperReadOnly <TKey, TType, TValue>(property);
public Start(NDReadOnlyPropertyKey <TKey, TType, TValue> property, TType of) : base(property) { this.of = of; }
public static IBindingConfigurator <TKey, TType, TValue> Of <TKey, TType, TValue>(this NDReadOnlyPropertyKey <TKey, TType, TValue> property, TType of) where TType : class { return(new Start <TKey, TType, TValue>(property, of)); }
internal NDBasePropertyKey(TValue defaultValue, NDPropertySettings settigns) : base(defaultValue, settigns) { ReadOnlyProperty = new NDReadOnlyPropertyKey <TKey, TType, TValue>(defaultValue, settigns); }