Esempio n. 1
0
        /// <summary>
        /// Constructs a NotifyProperty
        /// </summary>
        /// <param name="notifyPropertyChanged">The event source</param>
        /// <param name="propertyName">The name of the property</param>
        /// <param name="valueGet">Getter. Defaults to getting from the backing field</param>
        /// <param name="valueSet">Setter. Defaults to setting the backing field</param>
        /// <param name="valueSetCallback">Logic that occurs after valueSet but before raising PropertyChanged on the event source</param>
        /// <param name="checkConsiderEqual">Comparison check to determine whether or not PropertyChanged is raised. If true PropertyChanged is not raised. If false, PropertyChanged is raised</param>
        internal NotifyProperty(
            INotifyPropertyChanged notifyPropertyChanged,
            string propertyName,
            ValueGet <T> valueGet                = null,
            ValueSet <T> valueSet                = null,
            ValueSet <T> valueSetCallback        = null,
            CheckEquality <T> checkConsiderEqual = null
            )
        {
            _notifyPropertyChanged = notifyPropertyChanged ?? throw new ArgumentNullException(nameof(notifyPropertyChanged));
            _propertyName          = propertyName ?? throw new ArgumentNullException(nameof(propertyName));

            _valueSet = valueSet;
            _valueGet = valueGet;
            _beforePropertyChanged = valueSetCallback;
            _checkConsiderEqual    = checkConsiderEqual;

            if (_valueSet == null)
            {
                _valueSet = new ValueSet <T>((value) => _propertyValue = value);
            }

            if (_valueGet == null)
            {
                _valueGet = new ValueGet <T>(() => _propertyValue);
            }

            if (_checkConsiderEqual == null)
            {
                _checkConsiderEqual = new CheckEquality <T>((o, n) => EqualityComparer <T> .Default.Equals(o, n));
            }
        }
Esempio n. 2
0
 public static INotifyProperty <T> ConsiderValueEqualWhen <T>(this INotifyProperty <T> notifyProperty, CheckEquality <T> checkConsiderEqual)
 {
     notifyProperty.CheckConsiderEqual = checkConsiderEqual;
     return(notifyProperty);
 }
 public static bool CheckEqualityTests(object a, object b) => CheckEquality.CheckEqualityMethod(a, b);