コード例 #1
0
 /// <summary>
 /// Changes a field and notifies all registered receivers about a changed property,
 /// if the value of its field has changed.
 /// </summary>
 /// <typeparam name="TField">The type of the field.</typeparam>
 /// <param name="handler">The handler.</param>
 /// <param name="field">The field.</param>
 /// <param name="fieldValue">The field value.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <returns>True, if the field has changed and therefore the value has been updated, false otherwise</returns>
 public static bool ChangeAndNotify <TField>(this PropertyChangedEventHandler handler, ref TField field,
                                             TField fieldValue, object sender, string propertyName)
 {
     if (!Equals(field, fieldValue))
     {
         field = fieldValue;
         handler.Notify(sender, propertyName);
         return(true);
     }
     return(false);
 }
コード例 #2
0
        public static bool TryUpdateEnum <T>(this PropertyChangedEventHandler handler, INotifyPropertyChanged sender, ref T field, T value, [CallerMemberName] string propertyName = null) where T : Enum
        {
            if (field.Equals(value))
            {
                return(false);
            }
            var oldValue = field;

            field = value;
            handler.Notify(sender, oldValue, propertyName);
            return(true);
        }
コード例 #3
0
ファイル: Notifier.cs プロジェクト: sk8tz/Gu.Reactive
        internal static void Notify(
            object sender,
            NotifyCollectionChangedEventArgs change,
            IScheduler scheduler,
            PropertyChangedEventHandler propHandler,
            NotifyCollectionChangedEventHandler colHandler)
        {
            if ((propHandler == null && colHandler == null) || change == null)
            {
                return;
            }

            switch (change.Action)
            {
            case NotifyCollectionChangedAction.Add:
            case NotifyCollectionChangedAction.Remove:
                propHandler.Notify(sender, CountPropertyChangedEventArgs);
                propHandler.Notify(sender, IndexerPropertyChangedEventArgs);
                colHandler.Notify(sender, change, scheduler);
                break;

            case NotifyCollectionChangedAction.Replace:
            case NotifyCollectionChangedAction.Move:
                propHandler.Notify(sender, IndexerPropertyChangedEventArgs);
                colHandler.Notify(sender, change, scheduler);
                break;

            case NotifyCollectionChangedAction.Reset:
                propHandler.Notify(sender, CountPropertyChangedEventArgs);     // not sure if specialcasing is needed here.
                propHandler.Notify(sender, IndexerPropertyChangedEventArgs);
                colHandler.Notify(sender, change, scheduler);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }