示例#1
0
        public string this[string key]
        {
            get
            {
                if (key == null)
                {
                    return(null);
                }
                return(GetSafe <string>(() =>
                {
                    int index = IndexOf(key);
                    if (index < 0)
                    {
                        return null;
                    }
                    return _allItems[index].Value;
                }));
            }
            set
            {
                if (key == null)
                {
                    throw new ArgumentNullException();
                }

                InvokeSafe(() =>
                {
                    int index = IndexOf(key);
                    if (index < 0)
                    {
                        index = _allItems.Count;
                        _allItems.Add(new UriQueryItem(key, value));
                        _keyItemIndexes.Add(index);
                        EventQueueManager.Raise(PropertyName_Keys, RaisePropertyChanged);
                        EventQueueManager.Raise(PropertyName_Values, RaisePropertyChanged);
                        EventQueueManager.Raise(PropertyName_Count, RaisePropertyChanged);
                    }
                    else
                    {
                        UriQueryItem item = _allItems[index];
                        if ((item.Value == null) ? value == null : value != null && item.Value == value)
                        {
                            return;
                        }
                        item.Value = value;
                        EventQueueManager.Raise(PropertyName_Values, RaisePropertyChanged);
                    }
                });
            }
        }
示例#2
0
 private void InvokeSafe(Action method)
 {
     EventQueueManager.Invoke(_syncRoot, method);
 }
示例#3
0
 public UriQueryItem this[int index]
 {
     get { return(GetSafe <UriQueryItem>(() => _allItems[index])); }
     set
     {
         if (value == null)
         {
             throw new ArgumentNullException();
         }
         if (index < 0)
         {
             throw new IndexOutOfRangeException();
         }
         InvokeSafe(() =>
         {
             if (index == _allItems.Count)
             {
                 Add(value);
                 return;
             }
             UriQueryItem oldItem = _allItems[index];
             if (ReferenceEquals(oldItem, value))
             {
                 return;
             }
             for (int i = 0; i < _allItems.Count; i++)
             {
                 if (ReferenceEquals(_allItems[i], value))
                 {
                     MoveItem(i, index);
                     return;
                 }
             }
             oldItem.PropertyChanged -= Item_PropertyChanged;
             _allItems[index]         = value;
             value.PropertyChanged   += Item_PropertyChanged;
             if (_keyComparer.Equals(oldItem.Key, value.Key))
             {
                 if (IndexOf(oldItem.Key) == index)
                 {
                     if (oldItem.Key != value.Key)
                     {
                         EventQueueManager.Raise(PropertyName_Keys, RaisePropertyChanged);
                     }
                     if ((oldItem.Value == null) ? value.Value != null : (value.Value == null || oldItem.Value != value.Value))
                     {
                         EventQueueManager.Raise(PropertyName_Values, RaisePropertyChanged);
                     }
                 }
             }
             else
             {
                 int keyIndex = IndexOf(value.Key);
                 if (keyIndex > index)
                 {
                     _keyItemIndexes.Remove(keyIndex);
                 }
                 else if (keyIndex > -1)
                 {
                     _keyItemIndexes.Remove(index);
                 }
                 for (int i = index + 1; i < _allItems.Count; i++)
                 {
                     if (_keyComparer.Equals(_allItems[i].Key, oldItem.Key))
                     {
                         _keyItemIndexes.Add(i);
                         break;
                     }
                 }
                 EventQueueManager.Raise(PropertyName_Keys, RaisePropertyChanged);
                 EventQueueManager.Raise(PropertyName_Values, RaisePropertyChanged);
             }
         });
     }
 }
示例#4
0
 private T GetSafe <T>(Func <T> func)
 {
     return(EventQueueManager.Get(_syncRoot, func));
 }