public PropertyDependencyHandler(IRaisePropertyChanged caller)
 {
     _caller = caller;
     _caller.PropertyChanged += Caller_PropertyChanged;
     foreach (PropertyInfo property in caller.GetType().GetProperties())
     {
         PropertyDependency[] pDep = (PropertyDependency[])property.GetCustomAttributes(typeof(PropertyDependency));
         if (pDep.Length != 0)
         {
             propDepAttrs[property.Name] =
                 pDep.SelectMany(p => p.Dependency);
         }
         CollectionPropertyDependency[] cPDep = (CollectionPropertyDependency[])property.GetCustomAttributes(typeof(CollectionPropertyDependency));
         if (cPDep.Length != 0)
         {
             colPropDepAttrs[property.Name] =
                 new Pair <IEnumerable <string>, CollectionChangedClass> (cPDep.SelectMany(p => p.Dependency), null);
         }
         CollectionItemPropertyDependency[] cIPDep = (CollectionItemPropertyDependency[])property.GetCustomAttributes(typeof(CollectionItemPropertyDependency));
         if (cIPDep.Length != 0)
         {
             colItemPropDepAttrs[property.Name] =
                 new Pair <IEnumerable <Pair <IEnumerable <string>, IEnumerable <string> > >, ItemPropertyChangedClass>
                     (cIPDep.Select(p => new Pair <IEnumerable <string>, IEnumerable <string> >(p.TriggerItemDependency, p.Dependency)), null);
         }
         ChildPropertyDependency[] cCPDep = (ChildPropertyDependency[])property.GetCustomAttributes(typeof(ChildPropertyDependency));
         if (cCPDep.Length != 0)
         {
             colChildPropDepAttrs[property.Name] =
                 new Pair <IEnumerable <Pair <IEnumerable <string>, IEnumerable <string> > >, ChildPropertyChangedClass>
                     (cCPDep.Select(p => new Pair <IEnumerable <string>, IEnumerable <string> >(p.TriggerChildDependency, p.Dependency)), null);
         }
         Caller_PropertyChangedInner(this, new PropertyChangedEventArgs(property.Name), true);
     }
 }
 public static DerivedNotifyProperty <TValue> CreateDerivedNotifyProperty <TDependedProperty1, TDependedProperty2, TDependedProperty3, TDependedProperty4, TValue>(
     this IRaisePropertyChanged owner, Expression <Func <TValue> > derivedProperty,
     IProperty <TDependedProperty1> dependedProperty1, IProperty <TDependedProperty2> dependedProperty2, IProperty <TDependedProperty3> dependedProperty3, IProperty <TDependedProperty4> dependedProperty4,
     Func <TDependedProperty1, TDependedProperty2, TDependedProperty3, TDependedProperty4, TValue> getDerivedValueFunction)
 {
     return(CreateDerivedNotifyProperty(owner, derivedProperty.GetName(), dependedProperty1, dependedProperty2, dependedProperty3, dependedProperty4, getDerivedValueFunction));
 }
 public static DerivedNotifyProperty <TValue> CreateDerivedNotifyProperty <TDependedProperty1, TValue>(
     this IRaisePropertyChanged owner, string derivedPropertyName,
     IProperty <TDependedProperty1> dependedProperty, Func <TDependedProperty1, TValue> getDerivedValueFunction)
 {
     return(new DerivedNotifyProperty <TValue>(owner, derivedPropertyName,
                                               () => getDerivedValueFunction(dependedProperty.Value), dependedProperty));
 }
Exemple #4
0
 /// <summary>
 /// Creates a new PropertyChanged dependency register
 /// </summary>
 /// <param name="notifyInstance">The instance which notifies about property changes</param>
 /// <param name="raiseInstance">The instance which raises property change events</param>
 public PropertyChangedDependencies(INotifyPropertyChanged notifyInstance, IRaisePropertyChanged raiseInstance)
 {
     RuleLock       = new object();
     Rules          = new List <DependencyRule>();
     NotifyInstance = notifyInstance;
     RaiseInstance  = raiseInstance;
     NotifyInstance.PropertyChanged += HandlePropertyChanged;
 }
 public static DerivedNotifyProperty <TValue> CreateDerivedNotifyProperty <TDependedProperty1, TDependedProperty2, TDependedProperty3, TDependedProperty4, TValue>(
     this IRaisePropertyChanged owner, string derivedPropertyName,
     IProperty <TDependedProperty1> dependedProperty1, IProperty <TDependedProperty2> dependedProperty2, IProperty <TDependedProperty3> dependedProperty3, IProperty <TDependedProperty4> dependedProperty4,
     Func <TDependedProperty1, TDependedProperty2, TDependedProperty3, TDependedProperty4, TValue> getDerivedValueFunction)
 {
     return(new DerivedNotifyProperty <TValue>(owner, derivedPropertyName,
                                               () => getDerivedValueFunction(dependedProperty1.Value, dependedProperty2.Value, dependedProperty3.Value, dependedProperty4.Value), dependedProperty1, dependedProperty2, dependedProperty3, dependedProperty4));
 }
 public static void SetValueIfChanged <T>(this IRaisePropertyChanged source,
                                          ref T field,
                                          T value,
                                          [CallerMemberName] string propertyName = null)
 {
     // ReSharper disable once ExplicitCallerInfoArgument
     SetValueIfChanged(source, ref field, value, EqualityComparer <T> .Default, propertyName);
 }
    public static void RaisePropertyChanged <T>(
        this IRaisePropertyChanged raisePropertyChangedImpl,
        Expression <Func <T> > expr)
    {
        var    memberExprBody = expr.Body as MemberExpression;
        string property       = memberExprBody.Member.Name;

        raisePropertyChangedImpl.RaisePropertyChanged(property);
    }
        public PropertyChangedForwarder(IRaisePropertyChanged raiser, INotifyPropertyChanged notifier)
        {
            if (raiser == null)
                throw new ArgumentNullException(nameof(raiser));
            if (notifier == null)
                throw new ArgumentNullException(nameof(notifier));

            this.raiser = raiser;
            this.notifier = notifier;
            this.listeningProperties = new Dictionary<string, List<Action>>();
        }
Exemple #9
0
        /// <summary>
        /// Creates a notify property with the given owner and name
        /// </summary>
        /// <param name="owner">Object that contains this property, on which <see cref="INotifyPropertyChanged.PropertyChanged"/> events will be raised</param>
        /// <param name="name">Name of the property within its owner</param>
        /// <param name="initialValue">Initial value of the property</param>
        /// <param name="itemChangedComparer">Comparer that will be used to determine if the value has changed</param>
        public NotifyProperty(IRaisePropertyChanged owner, string name, T initialValue, IEqualityComparer <T> itemChangedComparer)
            : this(owner, name)
        {
            if (itemChangedComparer == null)
            {
                throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => itemChangedComparer));
            }
            this.m_itemChangedComparer = itemChangedComparer;

            this.m_value = initialValue;
        }
Exemple #10
0
        /// <summary>
        /// Creates a new <see cref="DerivedNotifyProperty&lt;TValue&gt;"/>.  When any of the specified properties change in the owner object, this property's value will be re-calculated the next time it is requested
        /// </summary>
        /// <param name="owner">Object that contains this property and the ones from which it is derived</param>
        /// <param name="derivedPropertyName">Name of this property in the owner</param>
        /// <param name="getDerivedPropertyValue">Function to determine the current value of this property</param>
        /// <param name="propertiesDependedOn">Properties that this value depends on.  When any of these properties change, this property's value will be re-calculated the next time it is requested.
        /// These properties must therefore be in the same owner object as this one.</param>
        public DerivedNotifyProperty(IRaisePropertyChanged owner, string derivedPropertyName, Func <TValue> getDerivedPropertyValue, params string[] propertiesDependedOn)
            : this(owner, derivedPropertyName, getDerivedPropertyValue)
        {
            this.m_owner.PropertyChanged += m_owner_PropertyChanged;

            if (propertiesDependedOn == null)
            {
                throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => propertiesDependedOn));
            }
            this.m_dependentValuesToListenFor = propertiesDependedOn.ToDictionary(property => property, property => true);
        }
Exemple #11
0
        /// <summary>
        /// Creates a new <see cref="DerivedNotifyProperty&lt;TValue&gt;"/>.  When any of the specified properties change, this property's value will be re-calculated the next time it is requested
        /// </summary>
        /// <param name="owner">Object that contains this property</param>
        /// <param name="derivedPropertyName">Name of this property in the owner</param>
        /// <param name="getDerivedPropertyValue">Function to determine the current value of this property</param>
        /// <param name="valueChangesToListenFor">Properties that this value depends on.  When any of these properties change, this property's value will be re-calculated the next time it is requested.</param>
        public DerivedNotifyProperty(IRaisePropertyChanged owner, string derivedPropertyName, Func <TValue> getDerivedPropertyValue, params INotifyValueChanged[] valueChangesToListenFor)
            : this(owner, derivedPropertyName, getDerivedPropertyValue)
        {
            if (valueChangesToListenFor == null)
            {
                throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => valueChangesToListenFor));
            }

            foreach (INotifyValueChanged valueChangeToListenFor in valueChangesToListenFor)
            {
                valueChangeToListenFor.ValueChanged += TriggerValueChanged;
            }
        }
        public static void SetValueIfDifferent<T>(this IRaisePropertyChanged sourceObject,
                                                  T value,
                                                  ref T field,
                                                  IEqualityComparer<T> equalityComparer,
                                                  [CallerMemberName] string propertyName = null)
        {
            if (equalityComparer.GetHashCode(value) == equalityComparer.GetHashCode(field) &&
                equalityComparer.Equals(value, field))
                return;

            field = value;
            sourceObject.RaisePropertyChanged(propertyName);
        }
        public static bool SetIfDifferent <T>(this IRaisePropertyChanged target, ref T field, T value, IEqualityComparer <T> comparer = null, [CallerMemberName] string memberName = null)
        {
            target.MustNotBeNull(nameof(target));
            comparer = comparer ?? EqualityComparer <T> .Default;

            if (comparer.EqualsWithHashCode(field, value))
            {
                return(false);
            }

            field = value;
            target.OnPropertyChanged(memberName);
            return(true);
        }
Exemple #14
0
        /// <summary>
        /// Creates a notify property with the given owner and name
        /// </summary>
        /// <param name="owner">Object that contains this property, on which <see cref="INotifyPropertyChanged.PropertyChanged"/> events will be raised</param>
        /// <param name="name">Name of the property within its owner</param>
        public NotifyProperty(IRaisePropertyChanged owner, string name)
        {
            if (owner == null)
            {
                throw new NotSupportedException("Null owners (e.g. static properties) are not supported");
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("No property name was specified", ObjectNamingExtensions.GetName(() => name));
            }

            this.m_owner = owner;
            this.m_name  = name;
            this.m_itemChangedComparer = EqualityComparer <T> .Default; //will be overwritten by other constructors if necessary
        }
        public static void SetValueIfChanged <T>(this IRaisePropertyChanged source,
                                                 ref T field,
                                                 T value,
                                                 IEqualityComparer <T> equalityComparer,
                                                 [CallerMemberName] string propertyName = null)
        {
            if (equalityComparer.GetHashCode(field) == equalityComparer.GetHashCode(value) &&
                equalityComparer.Equals(field, value))
            {
                return;
            }

            field = value;
            source.RaisePropertyChanged(propertyName);
        }
        /// <summary>
        /// Registers a <see cref="INotifyPropertyChanged.PropertyChanged"/> event. If events are not deferred, then the event is raised immediately.
        /// </summary>
        /// <param name="raisePropertyChanged">An object capable of raising <see cref="INotifyPropertyChanged.PropertyChanged"/>. May not be <c>null</c>.</param>
        /// <param name="args">The event arguments to pass to <see cref="INotifyPropertyChanged.PropertyChanged"/>.</param>
        public void Register(IRaisePropertyChanged raisePropertyChanged, PropertyChangedEventArgs args)
        {
            _threadAffinity.VerifyCurrentThread();
            if (raisePropertyChanged == null)
            {
                throw new ArgumentNullException(nameof(raisePropertyChanged));
            }

            if (_referenceCount == 0)
            {
                raisePropertyChanged.RaisePropertyChanged(args);
            }
            else
            {
                _propertiesRequiringNotification.Add(new PropertyChangedNotification(raisePropertyChanged, args));
            }
        }
Exemple #17
0
        private DerivedNotifyProperty(IRaisePropertyChanged owner, string derivedPropertyName, Func <TValue> getDerivedPropertyValue)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => owner));
            }
            this.m_owner = owner;

            if (string.IsNullOrEmpty(derivedPropertyName))
            {
                throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => derivedPropertyName));
            }
            this.m_derivedPropertyName = derivedPropertyName;

            if (getDerivedPropertyValue == null)
            {
                throw new ArgumentNullException(ObjectNamingExtensions.GetName(() => getDerivedPropertyValue));
            }
            this.m_getValueProperty = getDerivedPropertyValue;
            this.m_value            = new Lazy <TValue>(m_getValueProperty);
        }
Exemple #18
0
 /// <summary>
 /// Creates a new PropertyChanged child register
 /// </summary>
 /// <param name="raiseInstance">The instance which raises the PropertyChanged events</param>
 public PropertyChangedRouting(IRaisePropertyChanged raiseInstance)
 {
     RaiseInstance = raiseInstance;
 }
 /// <summary>
 /// Creates a new <see cref="IsBusyNotifyProperty"/> with the given owner and name
 /// </summary>
 /// <param name="owner">Object that contains the property</param>
 /// <param name="name">Name of this property within the parent object</param>
 public IsBusyNotifyProperty(IRaisePropertyChanged owner, string name)
     : base(owner, name)
 {
 }
 public PropertyChangedNotification(IRaisePropertyChanged raisePropertyChanged, PropertyChangedEventArgs eventArgs)
 {
     RaisePropertyChanged = raisePropertyChanged;
     EventArgs            = eventArgs;
 }
 /// <summary>
 /// Registers a <see cref="INotifyPropertyChanged.PropertyChanged"/> event. If events are not deferred, then the event is raised immediately.
 /// </summary>
 /// <param name="raisePropertyChanged">An object capable of raising <see cref="INotifyPropertyChanged.PropertyChanged"/>. May not be <c>null</c>.</param>
 /// <param name="propertyName">The name of the property that changed.</param>
 public void Register(IRaisePropertyChanged raisePropertyChanged, string propertyName)
 {
     _threadAffinity.VerifyCurrentThread();
     Register(raisePropertyChanged, PropertyChangedEventArgsCache.Instance.Get(propertyName));
 }
Exemple #22
0
 /// <summary>
 /// Creates a notify property with the given owner and name
 /// </summary>
 /// <param name="owner">Object that contains this property, on which <see cref="INotifyPropertyChanged.PropertyChanged"/> events will be raised</param>
 /// <param name="name">Name of the property within its owner</param>
 /// <param name="itemChangedComparer">Comparer that will be used to determine if the value has changed</param>
 public NotifyProperty(IRaisePropertyChanged owner, string name, IEqualityComparer <T> itemChangedComparer)
     : this(owner, name, default(T), itemChangedComparer)
 {
 }
Exemple #23
0
 /// <summary>
 /// Creates a notify property with the given owner and name
 /// </summary>
 /// <param name="owner">Object that contains this property, on which <see cref="INotifyPropertyChanged.PropertyChanged"/> events will be raised</param>
 /// <param name="name">Name of the property within its owner</param>
 /// <param name="initialValue">Initial value of the property</param>
 public NotifyProperty(IRaisePropertyChanged owner, string name, T initialValue)
     : this(owner, name, initialValue, EqualityComparer <T> .Default)
 {
 }
Exemple #24
0
 public static NotifyProperty <T> CreateNotifyProperty <T>(this IRaisePropertyChanged owner, Expression <Func <T> > nameExpression, T initialValue)
 {
     return(new NotifyProperty <T>(owner, nameExpression.GetName(), initialValue));
 }
 public static IsBusyNotifyProperty Create(IRaisePropertyChanged owner, Expression <Func <bool> > nameExpression)
 {
     return(new IsBusyNotifyProperty(owner, nameExpression.GetName()));
 }
Exemple #26
0
 public static NotifyProperty <T> CreateNotifyProperty <T>(this IRaisePropertyChanged owner, Expression <Func <T> > nameExpression, T initialValue, IEqualityComparer <T> itemChangedComparer)
 {
     return(new NotifyProperty <T>(owner, nameExpression.GetName(), initialValue, itemChangedComparer));
 }