<ItemGroup>
<Compile Include="System\Collections\Generic\DebugView.cs" />
<Compile Include="System\Collections\Specialized\INotifyCollectionChanged.cs" />
+ <Compile Include="System\Collections\Specialized\NotifyCollectionChangedAction.cs" />
<Compile Include="System\Collections\Specialized\NotifyCollectionChangedEventArgs.cs" />
<Compile Include="System\Collections\ObjectModel\KeyedCollection.cs" />
<Compile Include="System\Collections\ObjectModel\ObservableCollection.cs" />
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.Diagnostics;
namespace System.Collections.Generic
public CollectionDebugView(ICollection<T> collection)
{
- if (collection == null)
- throw new ArgumentNullException(nameof(collection));
-
- _collection = collection;
+ _collection = collection ?? throw new ArgumentNullException(nameof(collection));
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public DictionaryDebugView(IDictionary<K, V> dictionary)
{
- if (dictionary == null)
- throw new ArgumentNullException(nameof(dictionary));
-
- _dict = dictionary;
+ _dict = dictionary ?? throw new ArgumentNullException(nameof(dictionary));
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
}
}
}
-
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.Collections.Generic;
using System.Diagnostics;
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public abstract class KeyedCollection<TKey, TItem> : Collection<TItem>
{
- private const int defaultThreshold = 0;
+ private const int DefaultThreshold = 0;
private readonly IEqualityComparer<TKey> comparer; // Do not rename (binary serialization)
private Dictionary<TKey, TItem> dict; // Do not rename (binary serialization)
private int keyCount; // Do not rename (binary serialization)
private readonly int threshold; // Do not rename (binary serialization)
- protected KeyedCollection() : this(null, defaultThreshold) { }
-
- protected KeyedCollection(IEqualityComparer<TKey> comparer) : this(comparer, defaultThreshold) { }
+ protected KeyedCollection() : this(null, DefaultThreshold)
+ {
+ }
+ protected KeyedCollection(IEqualityComparer<TKey> comparer) : this(comparer, DefaultThreshold)
+ {
+ }
protected KeyedCollection(IEqualityComparer<TKey> comparer, int dictionaryCreationThreshold)
: base(new List<TItem>()) // Be explicit about the use of List<T> so we can foreach over
// Items internally without enumerator allocations.
{
- if (comparer == null)
- {
- comparer = EqualityComparer<TKey>.Default;
- }
-
- if (dictionaryCreationThreshold == -1)
- {
- dictionaryCreationThreshold = int.MaxValue;
- }
-
if (dictionaryCreationThreshold < -1)
{
throw new ArgumentOutOfRangeException(nameof(dictionaryCreationThreshold), SR.ArgumentOutOfRange_InvalidThreshold);
}
- this.comparer = comparer;
- threshold = dictionaryCreationThreshold;
+ this.comparer = comparer ?? EqualityComparer<TKey>.Default;
+ threshold = dictionaryCreationThreshold == -1 ? int.MaxValue : dictionaryCreationThreshold;
}
/// <summary>
/// Enables the use of foreach internally without allocations using <see cref="List{T}"/>'s struct enumerator.
/// </summary>
- new private List<TItem> Items
+ private new List<TItem> Items
{
get
{
Debug.Assert(base.Items is List<TItem>);
-
return (List<TItem>)base.Items;
}
}
- public IEqualityComparer<TKey> Comparer
- {
- get
- {
- return comparer;
- }
- }
+ public IEqualityComparer<TKey> Comparer => comparer;
public TItem this[TKey key]
{
foreach (TItem item in Items)
{
- if (comparer.Equals(GetKeyForItem(item), key)) return true;
+ if (comparer.Equals(GetKeyForItem(item), key))
+ {
+ return true;
+ }
}
+
return false;
}
return Items.Contains(item);
}
- TItem itemInDict;
- bool exist = dict.TryGetValue(key, out itemInDict);
- if (exist)
+ if (dict.TryGetValue(key, out TItem itemInDict))
{
return EqualityComparer<TItem>.Default.Equals(itemInDict, item);
}
+
return false;
}
if (dict != null)
{
- TItem item;
- return dict.TryGetValue(key, out item) && Remove(item);
+ return dict.TryGetValue(key, out TItem item) && Remove(item);
}
for (int i = 0; i < Items.Count; i++)
return true;
}
}
+
return false;
}
- protected IDictionary<TKey, TItem> Dictionary
- {
- get { return dict; }
- }
+ protected IDictionary<TKey, TItem> Dictionary => dict;
protected void ChangeItemKey(TItem item, TKey newKey)
{
- // Check if the item exists in the collection
if (!ContainsItem(item))
{
- throw new ArgumentException(SR.Argument_ItemNotExist);
+ throw new ArgumentException(SR.Argument_ItemNotExist, nameof(item));
}
TKey oldKey = GetKeyForItem(item);
{
AddKey(newKey, item);
}
-
if (oldKey != null)
{
RemoveKey(oldKey);
protected override void ClearItems()
{
base.ClearItems();
- if (dict != null)
- {
- dict.Clear();
- }
-
+ dict?.Clear();
keyCount = 0;
}
{
AddKey(key, item);
}
+
base.InsertItem(index, item);
}
{
RemoveKey(key);
}
+
base.RemoveItem(index);
}
RemoveKey(oldKey);
}
}
+
base.SetItem(index, item);
}
{
if (Contains(key))
{
- throw new ArgumentException(SR.Format(SR.Argument_AddingDuplicate, key));
+ throw new ArgumentException(SR.Format(SR.Argument_AddingDuplicate, key), nameof(key));
}
keyCount++;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
namespace System.Collections.ObjectModel
[System.Runtime.CompilerServices.TypeForwardedFrom("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public class ObservableCollection<T> : Collection<T>, INotifyCollectionChanged, INotifyPropertyChanged
{
- //------------------------------------------------------
- //
- // Private Fields
- //
- //------------------------------------------------------
-
- #region Private Fields
-
private SimpleMonitor _monitor; // Lazily allocated only when a subclass calls BlockReentrancy() or during serialization. Do not rename (binary serialization)
[NonSerialized]
private int _blockReentrancyCount;
- #endregion Private Fields
-
- //------------------------------------------------------
- //
- // Constructors
- //
- //------------------------------------------------------
- #region Constructors
/// <summary>
/// Initializes a new instance of ObservableCollection that is empty and has default initial capacity.
/// </summary>
- public ObservableCollection() { }
+ public ObservableCollection()
+ {
+ }
/// <summary>
/// Initializes a new instance of the ObservableCollection class that contains
/// same order they are read by the enumerator of the collection.
/// </remarks>
/// <exception cref="ArgumentNullException"> collection is a null reference </exception>
- public ObservableCollection(IEnumerable<T> collection) : base(CreateCopy(collection, nameof(collection))) { }
+ public ObservableCollection(IEnumerable<T> collection) : base(CreateCopy(collection, nameof(collection)))
+ {
+ }
/// <summary>
/// Initializes a new instance of the ObservableCollection class
/// same order they are read by the enumerator of the list.
/// </remarks>
/// <exception cref="ArgumentNullException"> list is a null reference </exception>
- public ObservableCollection(List<T> list) : base(CreateCopy(list, nameof(list))) { }
+ public ObservableCollection(List<T> list) : base(CreateCopy(list, nameof(list)))
+ {
+ }
private static List<T> CreateCopy(IEnumerable<T> collection, string paramName)
{
if (collection == null)
+ {
throw new ArgumentNullException(paramName);
+ }
return new List<T>(collection);
}
- #endregion Constructors
-
-
- //------------------------------------------------------
- //
- // Public Methods
- //
- //------------------------------------------------------
-
- #region Public Methods
-
/// <summary>
/// Move item at oldIndex to newIndex.
/// </summary>
- public void Move(int oldIndex, int newIndex)
- {
- MoveItem(oldIndex, newIndex);
- }
-
- #endregion Public Methods
+ public void Move(int oldIndex, int newIndex) => MoveItem(oldIndex, newIndex);
- //------------------------------------------------------
- //
- // Public Events
- //
- //------------------------------------------------------
-
- #region Public Events
-
- //------------------------------------------------------
- #region INotifyPropertyChanged implementation
-
/// <summary>
/// PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
/// </summary>
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
{
- add
- {
- PropertyChanged += value;
- }
- remove
- {
- PropertyChanged -= value;
- }
+ add => PropertyChanged += value;
+ remove => PropertyChanged -= value;
}
- #endregion INotifyPropertyChanged implementation
-
- //------------------------------------------------------
/// <summary>
/// Occurs when the collection changes, either by adding or removing an item.
/// </summary>
[field: NonSerialized]
public virtual event NotifyCollectionChangedEventHandler CollectionChanged;
- #endregion Public Events
-
-
- //------------------------------------------------------
- //
- // Protected Methods
- //
- //------------------------------------------------------
-
- #region Protected Methods
-
/// <summary>
/// Called by base class Collection<T> when the list is being cleared;
/// raises a CollectionChanged event to any listeners.
OnCollectionChanged(NotifyCollectionChangedAction.Move, removedItem, newIndex, oldIndex);
}
-
/// <summary>
/// Raises a PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
/// </summary>
}
}
- #endregion Protected Methods
-
-
- //------------------------------------------------------
- //
- // Private Methods
- //
- //------------------------------------------------------
-
- #region Private Methods
/// <summary>
/// Helper to raise a PropertyChanged event for the Count property
/// </summary>
- private void OnCountPropertyChanged()
- {
- OnPropertyChanged(EventArgsCache.CountPropertyChanged);
- }
+ private void OnCountPropertyChanged() => OnPropertyChanged(EventArgsCache.CountPropertyChanged);
/// <summary>
/// Helper to raise a PropertyChanged event for the Indexer property
/// </summary>
- private void OnIndexerPropertyChanged()
- {
- OnPropertyChanged(EventArgsCache.IndexerPropertyChanged);
- }
+ private void OnIndexerPropertyChanged() => OnPropertyChanged(EventArgsCache.IndexerPropertyChanged);
/// <summary>
/// Helper to raise CollectionChanged event to any listeners
/// <summary>
/// Helper to raise CollectionChanged event with action == Reset to any listeners
/// </summary>
- private void OnCollectionReset()
- {
- OnCollectionChanged(EventArgsCache.ResetCollectionChanged);
- }
+ private void OnCollectionReset() => OnCollectionChanged(EventArgsCache.ResetCollectionChanged);
private SimpleMonitor EnsureMonitorInitialized()
{
_monitor._collection = this;
}
}
- #endregion Private Methods
-
- //------------------------------------------------------
- //
- // Private Types
- //
- //------------------------------------------------------
-
- #region Private Types
// this class helps prevent reentrant calls
[Serializable]
- [System.Runtime.CompilerServices.TypeForwardedFrom("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
+ [TypeForwardedFrom("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
private sealed class SimpleMonitor : IDisposable
{
internal int _busyCount; // Only used during (de)serialization to maintain compatibility with desktop. Do not rename (binary serialization)
_collection = collection;
}
- public void Dispose()
- {
- _collection._blockReentrancyCount--;
- }
+ public void Dispose() => _collection._blockReentrancyCount--;
}
-
- #endregion Private Types
}
internal static class EventArgsCache
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
{
- if (dictionary == null)
- {
- throw new ArgumentNullException(nameof(dictionary));
- }
- m_dictionary = dictionary;
+ m_dictionary = dictionary ?? throw new ArgumentNullException(nameof(dictionary));
}
- protected IDictionary<TKey, TValue> Dictionary
- {
- get { return m_dictionary; }
- }
+ protected IDictionary<TKey, TValue> Dictionary => m_dictionary;
public KeyCollection Keys
{
- get
- {
- if (_keys == null)
- {
- _keys = new KeyCollection(m_dictionary.Keys);
- }
- return _keys;
- }
+ get => _keys ?? (_keys = new KeyCollection(m_dictionary.Keys));
}
public ValueCollection Values
{
- get
- {
- if (_values == null)
- {
- _values = new ValueCollection(m_dictionary.Values);
- }
- return _values;
- }
+ get => _values ?? (_values = new ValueCollection(m_dictionary.Values));
}
- #region IDictionary<TKey, TValue> Members
+ public bool ContainsKey(TKey key) => m_dictionary.ContainsKey(key);
- public bool ContainsKey(TKey key)
- {
- return m_dictionary.ContainsKey(key);
- }
-
- ICollection<TKey> IDictionary<TKey, TValue>.Keys
- {
- get
- {
- return Keys;
- }
- }
+ ICollection<TKey> IDictionary<TKey, TValue>.Keys => Keys;
public bool TryGetValue(TKey key, out TValue value)
{
return m_dictionary.TryGetValue(key, out value);
}
- ICollection<TValue> IDictionary<TKey, TValue>.Values
- {
- get
- {
- return Values;
- }
- }
+ ICollection<TValue> IDictionary<TKey, TValue>.Values => Values;
- public TValue this[TKey key]
- {
- get
- {
- return m_dictionary[key];
- }
- }
+ public TValue this[TKey key] => m_dictionary[key];
void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
{
TValue IDictionary<TKey, TValue>.this[TKey key]
{
- get
- {
- return m_dictionary[key];
- }
- set
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
+ get => m_dictionary[key];
+ set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- #endregion
-
- #region ICollection<KeyValuePair<TKey, TValue>> Members
-
- public int Count
- {
- get { return m_dictionary.Count; }
- }
+ public int Count => m_dictionary.Count;
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
{
m_dictionary.CopyTo(array, arrayIndex);
}
- bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
- {
- get { return true; }
- }
+ bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => true;
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- #endregion
-
- #region IEnumerable<KeyValuePair<TKey, TValue>> Members
-
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return m_dictionary.GetEnumerator();
}
- #endregion
-
- #region IEnumerable Members
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)m_dictionary).GetEnumerator();
}
- #endregion
-
- #region IDictionary Members
-
private static bool IsCompatibleKey(object key)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
+
return key is TKey;
}
return new DictionaryEnumerator(m_dictionary);
}
- bool IDictionary.IsFixedSize
- {
- get { return true; }
- }
+ bool IDictionary.IsFixedSize => true;
- bool IDictionary.IsReadOnly
- {
- get { return true; }
- }
+ bool IDictionary.IsReadOnly => true;
- ICollection IDictionary.Keys
- {
- get
- {
- return Keys;
- }
- }
+ ICollection IDictionary.Keys => Keys;
void IDictionary.Remove(object key)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- ICollection IDictionary.Values
- {
- get
- {
- return Values;
- }
- }
+ ICollection IDictionary.Values => Values;
object IDictionary.this[object key]
{
get
{
- if (IsCompatibleKey(key))
+ if (!IsCompatibleKey(key))
{
- return this[(TKey)key];
+ return null;
}
- return null;
- }
- set
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
+
+ return this[(TKey)key];
}
+ set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
void ICollection.CopyTo(Array array, int index)
{
throw new ArgumentNullException(nameof(array));
}
-
if (array.Rank != 1)
{
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);
+ throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
}
-
if (array.GetLowerBound(0) != 0)
{
- throw new ArgumentException(SR.Arg_NonZeroLowerBound);
+ throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array));
}
-
if (index < 0 || index > array.Length)
{
throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
}
-
if (array.Length - index < Count)
{
throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
object[] objects = array as object[];
if (objects == null)
{
- throw new ArgumentException(SR.Argument_InvalidArrayType);
+ throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array));
}
try
}
catch (ArrayTypeMismatchException)
{
- throw new ArgumentException(SR.Argument_InvalidArrayType);
+ throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array));
}
}
}
}
- bool ICollection.IsSynchronized
- {
- get { return false; }
- }
+ bool ICollection.IsSynchronized => false;
- object ICollection.SyncRoot
- {
- get
- {
- return (m_dictionary is ICollection coll) ? coll.SyncRoot : this;
- }
- }
+ object ICollection.SyncRoot => (m_dictionary is ICollection coll) ? coll.SyncRoot : this;
private struct DictionaryEnumerator : IDictionaryEnumerator
{
public DictionaryEntry Entry
{
- get { return new DictionaryEntry(_enumerator.Current.Key, _enumerator.Current.Value); }
- }
-
- public object Key
- {
- get { return _enumerator.Current.Key; }
+ get => new DictionaryEntry(_enumerator.Current.Key, _enumerator.Current.Value);
}
- public object Value
- {
- get { return _enumerator.Current.Value; }
- }
+ public object Key => _enumerator.Current.Key;
- public object Current
- {
- get { return Entry; }
- }
+ public object Value => _enumerator.Current.Value;
- public bool MoveNext()
- {
- return _enumerator.MoveNext();
- }
+ public object Current => Entry;
- public void Reset()
- {
- _enumerator.Reset();
- }
- }
+ public bool MoveNext() => _enumerator.MoveNext();
- #endregion
-
- #region IReadOnlyDictionary members
-
- IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys
- {
- get
- {
- return Keys;
- }
+ public void Reset() => _enumerator.Reset();
}
- IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values
- {
- get
- {
- return Values;
- }
- }
+ IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys => Keys;
- #endregion IReadOnlyDictionary members
+ IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values => Values;
[DebuggerTypeProxy(typeof(CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
internal KeyCollection(ICollection<TKey> collection)
{
- if (collection == null)
- {
- throw new ArgumentNullException(nameof(collection));
- }
- _collection = collection;
+ _collection = collection ?? throw new ArgumentNullException(nameof(collection));
}
- #region ICollection<T> Members
-
void ICollection<TKey>.Add(TKey item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
_collection.CopyTo(array, arrayIndex);
}
- public int Count
- {
- get { return _collection.Count; }
- }
+ public int Count => _collection.Count;
- bool ICollection<TKey>.IsReadOnly
- {
- get { return true; }
- }
+ bool ICollection<TKey>.IsReadOnly => true;
bool ICollection<TKey>.Remove(TKey item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- #endregion
-
- #region IEnumerable<T> Members
-
- public IEnumerator<TKey> GetEnumerator()
- {
- return _collection.GetEnumerator();
- }
-
- #endregion
-
- #region IEnumerable Members
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return ((IEnumerable)_collection).GetEnumerator();
- }
-
- #endregion
+ public IEnumerator<TKey> GetEnumerator() => _collection.GetEnumerator();
- #region ICollection Members
+ IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_collection).GetEnumerator();
void ICollection.CopyTo(Array array, int index)
{
ReadOnlyDictionaryHelpers.CopyToNonGenericICollectionHelper<TKey>(_collection, array, index);
}
- bool ICollection.IsSynchronized
- {
- get { return false; }
- }
+ bool ICollection.IsSynchronized => false;
- object ICollection.SyncRoot
- {
- get
- {
- return (_collection is ICollection coll) ? coll.SyncRoot : this;
- }
- }
- #endregion
+ object ICollection.SyncRoot => (_collection is ICollection coll) ? coll.SyncRoot : this;
}
[DebuggerTypeProxy(typeof(CollectionDebugView<>))]
internal ValueCollection(ICollection<TValue> collection)
{
- if (collection == null)
- {
- throw new ArgumentNullException(nameof(collection));
- }
- _collection = collection;
+ _collection = collection ?? throw new ArgumentNullException(nameof(collection));
}
- #region ICollection<T> Members
-
void ICollection<TValue>.Add(TValue item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- bool ICollection<TValue>.Contains(TValue item)
- {
- return _collection.Contains(item);
- }
+ bool ICollection<TValue>.Contains(TValue item) => _collection.Contains(item);
public void CopyTo(TValue[] array, int arrayIndex)
{
_collection.CopyTo(array, arrayIndex);
}
- public int Count
- {
- get { return _collection.Count; }
- }
+ public int Count => _collection.Count;
- bool ICollection<TValue>.IsReadOnly
- {
- get { return true; }
- }
+ bool ICollection<TValue>.IsReadOnly => true;
bool ICollection<TValue>.Remove(TValue item)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
+ public IEnumerator<TValue> GetEnumerator() => _collection.GetEnumerator();
- #endregion
-
- #region IEnumerable<T> Members
-
- public IEnumerator<TValue> GetEnumerator()
- {
- return _collection.GetEnumerator();
- }
-
- #endregion
-
- #region IEnumerable Members
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
- {
- return ((IEnumerable)_collection).GetEnumerator();
- }
-
- #endregion
-
- #region ICollection Members
+ IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_collection).GetEnumerator();
void ICollection.CopyTo(Array array, int index)
{
ReadOnlyDictionaryHelpers.CopyToNonGenericICollectionHelper<TValue>(_collection, array, index);
}
- bool ICollection.IsSynchronized
- {
- get { return false; }
- }
-
- object ICollection.SyncRoot
- {
- get
- {
- return (_collection is ICollection coll) ? coll.SyncRoot : this;
- }
- }
+ bool ICollection.IsSynchronized => false;
- #endregion ICollection Members
+ object ICollection.SyncRoot => (_collection is ICollection coll) ? coll.SyncRoot : this;
}
}
// To share code when possible, use a non-generic class to get rid of irrelevant type parameters.
internal static class ReadOnlyDictionaryHelpers
{
- #region Helper method for our KeyCollection and ValueCollection
-
// Abstracted away to avoid redundant implementations.
internal static void CopyToNonGenericICollectionHelper<T>(ICollection<T> collection, Array array, int index)
{
{
throw new ArgumentNullException(nameof(array));
}
-
if (array.Rank != 1)
{
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);
+ throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array));
}
-
if (array.GetLowerBound(0) != 0)
{
- throw new ArgumentException(SR.Arg_NonZeroLowerBound);
+ throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array));
}
-
if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
}
-
if (array.Length - index < collection.Count)
{
throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
}
else
{
- /*
- FxOverRh: Type.IsAssignableNot() not an api on that platform.
-
- //
- // Catch the obvious case assignment will fail.
- // We can found all possible problems by doing the check though.
- // For example, if the element type of the Array is derived from T,
- // we can't figure out if we can successfully copy the element beforehand.
- //
- Type targetType = array.GetType().GetElementType();
- Type sourceType = typeof(T);
- if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType))) {
- throw new ArgumentException(SR.Argument_InvalidArrayType);
- }
- */
-
- //
// We can't cast array of value type to object[], so we don't support
// widening of primitive types here.
- //
object[] objects = array as object[];
if (objects == null)
{
- throw new ArgumentException(SR.Argument_InvalidArrayType);
+ throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array));
}
try
}
catch (ArrayTypeMismatchException)
{
- throw new ArgumentException(SR.Argument_InvalidArrayType);
+ throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array));
}
}
}
- #endregion Helper method for our KeyCollection and ValueCollection
}
}
-
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
[Serializable]
[DebuggerTypeProxy(typeof(CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
- [System.Runtime.CompilerServices.TypeForwardedFrom("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
+ [TypeForwardedFrom("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public class ReadOnlyObservableCollection<T> : ReadOnlyCollection<T>, INotifyCollectionChanged, INotifyPropertyChanged
{
- #region Constructors
-
- //------------------------------------------------------
- //
- // Constructors
- //
- //------------------------------------------------------
-
/// <summary>
/// Initializes a new instance of ReadOnlyObservableCollection that
/// wraps the given ObservableCollection.
((INotifyPropertyChanged)Items).PropertyChanged += new PropertyChangedEventHandler(HandlePropertyChanged);
}
- #endregion Constructors
-
- #region Interfaces
-
- //------------------------------------------------------
- //
- // Interfaces
- //
- //------------------------------------------------------
-
- #region INotifyCollectionChanged
-
/// <summary>
/// CollectionChanged event (per <see cref="INotifyCollectionChanged" />).
/// </summary>
event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
{
- add { CollectionChanged += value; }
- remove { CollectionChanged -= value; }
+ add => CollectionChanged += value;
+ remove => CollectionChanged -= value;
}
/// <summary>
/// </summary>
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
{
- if (CollectionChanged != null)
- {
- CollectionChanged(this, args);
- }
+ CollectionChanged?.Invoke(this, args);
}
- #endregion INotifyCollectionChanged
-
- #region INotifyPropertyChanged
-
/// <summary>
/// PropertyChanged event (per <see cref="INotifyPropertyChanged" />).
/// </summary>
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
{
- add { PropertyChanged += value; }
- remove { PropertyChanged -= value; }
+ add => PropertyChanged += value;
+ remove => PropertyChanged -= value;
}
/// <summary>
/// </summary>
protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
{
- if (PropertyChanged != null)
- {
- PropertyChanged(this, args);
- }
+ PropertyChanged?.Invoke(this, args);
}
- #endregion INotifyPropertyChanged
-
- #endregion Interfaces
-
- #region Private Methods
-
- //------------------------------------------------------
- //
- // Private Methods
- //
- //------------------------------------------------------
-
- // forward CollectionChanged events from the base list to our listeners
private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
OnCollectionChanged(e);
}
- // forward PropertyChanged events from the base list to our listeners
private void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged(e);
}
- #endregion Private Methods
}
}
-
-
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Runtime.CompilerServices;
-
namespace System.Collections.Specialized
{
/// <summary>
event NotifyCollectionChangedEventHandler CollectionChanged;
}
}
-
-
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+namespace System.Collections.Specialized
+{
+ /// <summary>
+ /// This enum describes the action that caused a CollectionChanged event.
+ /// </summary>
+ public enum NotifyCollectionChangedAction
+ {
+ /// <summary>
+ /// One or more items were added to the collection.
+ /// </summary>
+ Add,
+
+ /// <summary>
+ /// One or more items were removed from the collection.
+ /// </summary>
+ Remove,
+
+ /// <summary>
+ /// One or more items were replaced in the collection.
+ /// </summary>
+ Replace,
+
+ /// <summary>
+ /// One or more items were moved within the collection.
+ /// </summary>
+ Move,
+
+ /// <summary>
+ /// The contents of the collection changed dramatically.
+ /// </summary>
+ Reset,
+ }
+}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Collections;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace System.Collections.Specialized
{
/// <summary>
- /// This enum describes the action that caused a CollectionChanged event.
- /// </summary>
- public enum NotifyCollectionChangedAction
- {
- /// <summary> One or more items were added to the collection. </summary>
- Add,
- /// <summary> One or more items were removed from the collection. </summary>
- Remove,
- /// <summary> One or more items were replaced in the collection. </summary>
- Replace,
- /// <summary> One or more items were moved within the collection. </summary>
- Move,
- /// <summary> The contents of the collection changed dramatically. </summary>
- Reset,
- }
-
- /// <summary>
/// Arguments for the CollectionChanged event.
/// A collection that supports INotifyCollectionChangedThis raises this event
/// whenever an item is added or removed, or when the contents of the collection
/// </summary>
public class NotifyCollectionChangedEventArgs : EventArgs
{
- //------------------------------------------------------
- //
- // Constructors
- //
- //------------------------------------------------------
+ private NotifyCollectionChangedAction _action;
+ private IList _newItems;
+ private IList _oldItems;
+ private int _newStartingIndex = -1;
+ private int _oldStartingIndex = -1;
/// <summary>
/// Construct a NotifyCollectionChangedEventArgs that describes a reset change.
public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action)
{
if (action != NotifyCollectionChangedAction.Reset)
+ {
throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Reset), nameof(action));
+ }
InitializeAdd(action, null, -1);
}
{
if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
&& (action != NotifyCollectionChangedAction.Reset))
+ {
throw new ArgumentException(SR.MustBeResetAddOrRemoveActionForCtor, nameof(action));
+ }
if (action == NotifyCollectionChangedAction.Reset)
{
if (changedItem != null)
+ {
throw new ArgumentException(SR.ResetActionRequiresNullItem, nameof(action));
+ }
InitializeAdd(action, null, -1);
}
{
if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
&& (action != NotifyCollectionChangedAction.Reset))
+ {
throw new ArgumentException(SR.MustBeResetAddOrRemoveActionForCtor, nameof(action));
+ }
if (action == NotifyCollectionChangedAction.Reset)
{
if (changedItem != null)
+ {
throw new ArgumentException(SR.ResetActionRequiresNullItem, nameof(action));
+ }
if (index != -1)
+ {
throw new ArgumentException(SR.ResetActionRequiresIndexMinus1, nameof(action));
+ }
InitializeAdd(action, null, -1);
}
{
if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
&& (action != NotifyCollectionChangedAction.Reset))
+ {
throw new ArgumentException(SR.MustBeResetAddOrRemoveActionForCtor, nameof(action));
+ }
if (action == NotifyCollectionChangedAction.Reset)
{
if (changedItems != null)
+ {
throw new ArgumentException(SR.ResetActionRequiresNullItem, nameof(action));
+ }
InitializeAdd(action, null, -1);
}
else
{
if (changedItems == null)
+ {
throw new ArgumentNullException(nameof(changedItems));
+ }
InitializeAddOrRemove(action, changedItems, -1);
}
{
if ((action != NotifyCollectionChangedAction.Add) && (action != NotifyCollectionChangedAction.Remove)
&& (action != NotifyCollectionChangedAction.Reset))
+ {
throw new ArgumentException(SR.MustBeResetAddOrRemoveActionForCtor, nameof(action));
+ }
if (action == NotifyCollectionChangedAction.Reset)
{
if (changedItems != null)
+ {
throw new ArgumentException(SR.ResetActionRequiresNullItem, nameof(action));
+ }
if (startingIndex != -1)
+ {
throw new ArgumentException(SR.ResetActionRequiresIndexMinus1, nameof(action));
+ }
InitializeAdd(action, null, -1);
}
else
{
if (changedItems == null)
+ {
throw new ArgumentNullException(nameof(changedItems));
+ }
if (startingIndex < -1)
+ {
throw new ArgumentException(SR.IndexCannotBeNegative, nameof(startingIndex));
+ }
InitializeAddOrRemove(action, changedItems, startingIndex);
}
public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object newItem, object oldItem)
{
if (action != NotifyCollectionChangedAction.Replace)
+ {
throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Replace), nameof(action));
+ }
InitializeMoveOrReplace(action, new object[] { newItem }, new object[] { oldItem }, -1, -1);
}
public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object newItem, object oldItem, int index)
{
if (action != NotifyCollectionChangedAction.Replace)
+ {
throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Replace), nameof(action));
+ }
InitializeMoveOrReplace(action, new object[] { newItem }, new object[] { oldItem }, index, index);
}
public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList newItems, IList oldItems)
{
if (action != NotifyCollectionChangedAction.Replace)
+ {
throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Replace), nameof(action));
+ }
if (newItems == null)
+ {
throw new ArgumentNullException(nameof(newItems));
+ }
if (oldItems == null)
+ {
throw new ArgumentNullException(nameof(oldItems));
+ }
InitializeMoveOrReplace(action, newItems, oldItems, -1, -1);
}
public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList newItems, IList oldItems, int startingIndex)
{
if (action != NotifyCollectionChangedAction.Replace)
+ {
throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Replace), nameof(action));
+ }
if (newItems == null)
+ {
throw new ArgumentNullException(nameof(newItems));
+ }
if (oldItems == null)
+ {
throw new ArgumentNullException(nameof(oldItems));
+ }
InitializeMoveOrReplace(action, newItems, oldItems, startingIndex, startingIndex);
}
public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, object changedItem, int index, int oldIndex)
{
if (action != NotifyCollectionChangedAction.Move)
+ {
throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Move), nameof(action));
+ }
if (index < 0)
+ {
throw new ArgumentException(SR.IndexCannotBeNegative, nameof(index));
+ }
object[] changedItems = new object[] { changedItem };
InitializeMoveOrReplace(action, changedItems, changedItems, index, oldIndex);
public NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction action, IList changedItems, int index, int oldIndex)
{
if (action != NotifyCollectionChangedAction.Move)
+ {
throw new ArgumentException(SR.Format(SR.WrongActionForCtor, NotifyCollectionChangedAction.Move), nameof(action));
+ }
if (index < 0)
+ {
throw new ArgumentException(SR.IndexCannotBeNegative, nameof(index));
+ }
InitializeMoveOrReplace(action, changedItems, changedItems, index, oldIndex);
}
private void InitializeAddOrRemove(NotifyCollectionChangedAction action, IList changedItems, int startingIndex)
{
if (action == NotifyCollectionChangedAction.Add)
+ {
InitializeAdd(action, changedItems, startingIndex);
- else if (action == NotifyCollectionChangedAction.Remove)
- InitializeRemove(action, changedItems, startingIndex);
+ }
else
- Debug.Assert(false, string.Format("Unsupported action: {0}", action.ToString()));
+ {
+ Debug.Assert(action == NotifyCollectionChangedAction.Remove, $"Unsupported action: {action}");
+ InitializeRemove(action, changedItems, startingIndex);
+ }
}
private void InitializeAdd(NotifyCollectionChangedAction action, IList newItems, int newStartingIndex)
InitializeRemove(action, oldItems, oldStartingIndex);
}
- //------------------------------------------------------
- //
- // Public Properties
- //
- //------------------------------------------------------
-
/// <summary>
/// The action that caused the event.
/// </summary>
- public NotifyCollectionChangedAction Action
- {
- get { return _action; }
- }
+ public NotifyCollectionChangedAction Action => _action;
/// <summary>
/// The items affected by the change.
/// </summary>
- public IList NewItems
- {
- get { return _newItems; }
- }
+ public IList NewItems => _newItems;
/// <summary>
/// The old items affected by the change (for Replace events).
/// </summary>
- public IList OldItems
- {
- get { return _oldItems; }
- }
+ public IList OldItems => _oldItems;
/// <summary>
/// The index where the change occurred.
/// </summary>
- public int NewStartingIndex
- {
- get { return _newStartingIndex; }
- }
+ public int NewStartingIndex => _newStartingIndex;
/// <summary>
/// The old index where the change occurred (for Move events).
/// </summary>
- public int OldStartingIndex
- {
- get { return _oldStartingIndex; }
- }
-
- //------------------------------------------------------
- //
- // Private Fields
- //
- //------------------------------------------------------
-
- private NotifyCollectionChangedAction _action;
- private IList _newItems, _oldItems;
- private int _newStartingIndex = -1;
- private int _oldStartingIndex = -1;
+ public int OldStartingIndex => _oldStartingIndex;
}
/// <summary>
- /// The delegate to use for handlers that receive the CollectionChanged event.
+ /// The delegate to use for handlers that receive the CollectionChanged event.
/// </summary>
public delegate void NotifyCollectionChangedEventHandler(object sender, NotifyCollectionChangedEventArgs e);
-
internal sealed class ReadOnlyList : IList
{
private readonly IList _list;
internal ReadOnlyList(IList list)
{
Debug.Assert(list != null);
-
_list = list;
}
- public int Count
- {
- get { return _list.Count; }
- }
+ public int Count => _list.Count;
- public bool IsReadOnly
- {
- get { return true; }
- }
+ public bool IsReadOnly => true;
- public bool IsFixedSize
- {
- get { return true; }
- }
+ public bool IsFixedSize => true;
- public bool IsSynchronized
- {
- get { return _list.IsSynchronized; }
- }
+ public bool IsSynchronized => _list.IsSynchronized;
public object this[int index]
{
- get
- {
- return _list[index];
- }
- set
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
+ get => _list[index];
+ set => throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- public object SyncRoot
- {
- get { return _list.SyncRoot; }
- }
+ public object SyncRoot => _list.SyncRoot;
public int Add(object value)
{
throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
}
- public bool Contains(object value)
- {
- return _list.Contains(value);
- }
+ public bool Contains(object value) => _list.Contains(value);
public void CopyTo(Array array, int index)
{
_list.CopyTo(array, index);
}
- public IEnumerator GetEnumerator()
- {
- return _list.GetEnumerator();
- }
+ public IEnumerator GetEnumerator() => _list.GetEnumerator();
- public int IndexOf(object value)
- {
- return _list.IndexOf(value);
- }
+ public int IndexOf(object value) => _list.IndexOf(value);
public void Insert(int index, object value)
{
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Diagnostics;
-
namespace System.ComponentModel
{
- /// <devdoc>
- /// <para>Provides data for the <see langword='ErrorsChanged'/>
- /// event.</para>
- /// </devdoc>
+ /// <summary>
+ /// Provides data for the <see langword='ErrorsChanged'/> event.
+ /// </summary>
public class DataErrorsChangedEventArgs : EventArgs
{
- private readonly string _propertyName;
-
- /// <devdoc>
- /// <para>Initializes a new instance of the <see cref='System.ComponentModel.DataErrorsChangedEventArgs'/>
- /// class.</para>
- /// </devdoc>
+ /// <summary>
+ /// Initializes a new instance of the <see cref='System.ComponentModel.DataErrorsChangedEventArgs'/>
+ /// class.
+ /// </summary>
public DataErrorsChangedEventArgs(string propertyName)
{
- _propertyName = propertyName;
+ PropertyName = propertyName;
}
- /// <devdoc>
- /// <para>Indicates the name of the property whose errors changed.</para>
- /// </devdoc>
- public virtual string PropertyName
- {
- get
- {
- return _propertyName;
- }
- }
+ /// <summary>
+ /// Indicates the name of the property whose errors changed.
+ /// </summary>
+ public virtual string PropertyName { get; }
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.Collections;
namespace System.ComponentModel
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Diagnostics;
-
namespace System.ComponentModel
{
- /// <devdoc>
- /// <para>Provides data for the <see langword='PropertyChanged'/>
- /// event.</para>
- /// </devdoc>
+ /// <summary>
+ /// Provides data for the <see langword='PropertyChanged'/> event.
+ /// </summary>
public class PropertyChangedEventArgs : EventArgs
{
- private readonly string _propertyName;
-
- /// <devdoc>
- /// <para>Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangedEventArgs'/>
- /// class.</para>
- /// </devdoc>
+ /// <summary>
+ /// Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangedEventArgs'/>
+ /// class.
+ /// </summary>
public PropertyChangedEventArgs(string propertyName)
{
- _propertyName = propertyName;
+ PropertyName = propertyName;
}
- /// <devdoc>
- /// <para>Indicates the name of the property that changed.</para>
- /// </devdoc>
- public virtual string PropertyName
- {
- get
- {
- return _propertyName;
- }
- }
+ /// <summary>
+ /// Indicates the name of the property that changed.
+ /// </summary>
+ public virtual string PropertyName { get; }
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Diagnostics;
-
namespace System.ComponentModel
{
- /// <devdoc>
- /// <para>Represents the method that will handle the
- /// <see langword='PropertyChanged'/> event raised when a
- /// property is changed on a component.</para>
- /// </devdoc>
+ /// <summary>
+ /// Represents the method that will handle the <see langword='PropertyChanged'/>
+ /// event raised when a property is changed on a component.
+ /// </summary>
public delegate void PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e);
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-
namespace System.ComponentModel
{
- /// <devdoc>
- /// <para>Provides data for the <see langword='PropertyChanging'/>
- /// event.</para>
- /// </devdoc>
+ /// <summary>
+ /// Provides data for the <see langword='PropertyChanging'/> event.
+ /// </summary>
public class PropertyChangingEventArgs : EventArgs
{
- private readonly string _propertyName;
-
- /// <devdoc>
- /// <para>Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangingEventArgs'/>
- /// class.</para>
- /// </devdoc>
+ /// <summary>
+ /// Initializes a new instance of the <see cref='System.ComponentModel.PropertyChangingEventArgs'/>
+ /// class.
+ /// </summary>
public PropertyChangingEventArgs(string propertyName)
{
- _propertyName = propertyName;
+ PropertyName = propertyName;
}
- /// <devdoc>
- /// <para>Indicates the name of the property that is changing.</para>
- /// </devdoc>
- public virtual string PropertyName
- {
- get
- {
- return _propertyName;
- }
- }
+ /// <summary>
+ /// Indicates the name of the property that is changing.
+ /// </summary>
+ public virtual string PropertyName { get; }
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-
namespace System.ComponentModel
{
- /// <devdoc>
- /// <para>Represents the method that will handle the
- /// <see langword='PropertyChanging'/> event raised when a
- /// property is changing on a component.</para>
- /// </devdoc>
+ /// <summary>
+ /// Represents the method that will handle the <see langword='PropertyChanging'/>
+ /// event raised when a property is changing on a component.
+ /// </summary>
public delegate void PropertyChangingEventHandler(object sender, PropertyChangingEventArgs e);
}
namespace System.ComponentModel
{
/// <summary>
- /// <para>
- /// Specifies what type to use as a converter for the object this
- /// attribute is bound to. This class cannot be inherited.
- /// </para>
+ /// Specifies what type to use as a converter for the object this attribute is
+ /// bound to. This class cannot be inherited.
/// </summary>
[AttributeUsage(AttributeTargets.All)]
public sealed class TypeConverterAttribute : Attribute
{
/// <summary>
- /// <para>
- /// Specifies the type to use as a converter for the object this attribute is bound to. This
- /// <see langword='static '/>field is read-only. </para>
+ /// Specifies the type to use as a converter for the object this attribute is
+ /// bound to. This <see langword='static '/>field is read-only.
/// </summary>
public static readonly TypeConverterAttribute Default = new TypeConverterAttribute();
/// <summary>
- /// <para>
- /// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/> class with the
- /// default type converter, which is an empty string ("").
- /// </para>
+ /// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/>
+ /// class with the default type converter, which is an empty string ("").
/// </summary>
public TypeConverterAttribute()
{
}
/// <summary>
- /// <para>
- /// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/> class,
- /// using the specified type as the data converter for the object this attribute is bound to.
- /// </para>
+ /// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/>
+ /// class, using the specified type as the data converter for the object this attribute
+ /// is bound to.
/// </summary>
public TypeConverterAttribute(Type type)
{
}
/// <summary>
- /// <para>
- /// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/> class,
- /// using the specified type name as the data converter for the object this attribute is bound to.
- /// </para>
+ /// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/>
+ /// class, using the specified type name as the data converter for the object this attribute
+ /// is bound to.
/// </summary>
public TypeConverterAttribute(string typeName)
{
}
/// <summary>
- /// <para>
- /// Gets the fully qualified type name of the <see cref='System.Type'/> to use as a converter for
- /// the object this attribute is bound to.
- /// </para>
+ /// Gets the fully qualified type name of the <see cref='System.Type'/> to use as a
+ /// converter for the object this attribute is bound to.
/// </summary>
public string ConverterTypeName { get; }
public override bool Equals(object obj)
{
- TypeConverterAttribute other = obj as TypeConverterAttribute;
- return (other != null) && other.ConverterTypeName == ConverterTypeName;
+ return
+ obj is TypeConverterAttribute other &&
+ other.ConverterTypeName == ConverterTypeName;
}
- public override int GetHashCode()
- {
- return ConverterTypeName.GetHashCode();
- }
+ public override int GetHashCode() => ConverterTypeName.GetHashCode();
}
}
Type GetCustomType();
}
}
-
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Markup;
namespace System.Windows.Input
{
///<summary>
- /// An interface that allows an application author to define a method to be invoked.
+ /// An interface that allows an application author to define a method to be invoked.
///</summary>
[TypeForwardedFrom("PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
[TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public interface ICommand
{
/// <summary>
- /// Raised when the ability of the command to execute has changed.
+ /// Raised when the ability of the command to execute has changed.
/// </summary>
event EventHandler CanExecuteChanged;
/// <summary>
- /// Returns whether the command can be executed.
+ /// Returns whether the command can be executed.
/// </summary>
/// <param name="parameter">A parameter that may be used in executing the command. This parameter may be ignored by some implementations.</param>
/// <returns>true if the command can be executed with the given parameter and current state. false otherwise.</returns>
bool CanExecute(object parameter);
/// <summary>
- /// Defines the method that should be executed when the command is executed.
+ /// Defines the method that should be executed when the command is executed.
/// </summary>
/// <param name="parameter">A parameter that may be used in executing the command. This parameter may be ignored by some implementations.</param>
void Execute(object parameter);
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
using System.Runtime.CompilerServices;
namespace System.Windows.Markup
public sealed class ValueSerializerAttribute : Attribute
{
private Type _valueSerializerType;
- private string _valueSerializerTypeName;
+ private readonly string _valueSerializerTypeName;
/// <summary>
/// Constructor for the ValueSerializerAttribute
get
{
if (_valueSerializerType == null && _valueSerializerTypeName != null)
+ {
_valueSerializerType = Type.GetType(_valueSerializerTypeName);
+ }
+
return _valueSerializerType;
}
}
get
{
if (_valueSerializerType != null)
+ {
return _valueSerializerType.AssemblyQualifiedName;
+ }
else
+ {
return _valueSerializerTypeName;
+ }
}
}
}
new KeyedItem<string, int>("foo", 0),
new KeyedItem<string, int>("bar", 1)
};
- AssertExtensions.Throws<ArgumentException>(null, () => collection.Add(new KeyedItem<string, int>("Foo", 0)));
- AssertExtensions.Throws<ArgumentException>(null, () => collection.Add(new KeyedItem<string, int>("fOo", 0)));
- AssertExtensions.Throws<ArgumentException>(null, () => collection.Add(new KeyedItem<string, int>("baR", 0)));
+ AssertExtensions.Throws<ArgumentException>("key", null, () => collection.Add(new KeyedItem<string, int>("Foo", 0)));
+ AssertExtensions.Throws<ArgumentException>("key", null, () => collection.Add(new KeyedItem<string, int>("fOo", 0)));
+ AssertExtensions.Throws<ArgumentException>("key", null, () => collection.Add(new KeyedItem<string, int>("baR", 0)));
}
- [Fact]
- public void ThresholdThrows()
+ [Theory]
+ [InlineData(-2)]
+ [InlineData(int.MinValue)]
+ public void Ctor_InvalidDictionaryCreationThreshold_ThrowsArgumentOutOfRangeException(int dictionaryCreationThreshold)
{
- Assert.Throws<ArgumentOutOfRangeException>(
- () =>
- new TestKeyedCollectionOfIKeyedItem<string, int>(-2));
- Assert.Throws<ArgumentOutOfRangeException>(
- () =>
- new TestKeyedCollectionOfIKeyedItem<string, int>(
- int.MinValue));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("dictionaryCreationThreshold", () => new TestKeyedCollectionOfIKeyedItem<string, int>(dictionaryCreationThreshold));
}
}
collection.Add(keyedItem1);
- AssertExtensions.Throws<ArgumentException>(null, () => collection.Add(tmpKeyedItem));
+ string expectedParamName = collectionSize < 32 || generateKeyedItem.Name != KeyedCollectionTests<TKey, TValue>.GetNeverNullKeyMethod.Name ? "key" : null;
+ AssertExtensions.Throws<ArgumentException>(expectedParamName, null, () => collection.Add(tmpKeyedItem));
collection.Verify(keys, items, itemsWithKeys);
}
collection.Add(keyedItem1);
- AssertExtensions.Throws<ArgumentException>(null, () => nonGenericCollection.Add(tmpKeyedItem));
+ string expectedParamName = collectionSize < 32 || generateKeyedItem.Name != KeyedCollectionTests<TKey, TValue>.GetNeverNullKeyMethod.Name ? "key" : null;
+ AssertExtensions.Throws<ArgumentException>(expectedParamName, null, () => nonGenericCollection.Add(tmpKeyedItem));
collection.Verify(keys, items, itemsWithKeys);
}
.ToArray
<IKeyedItem<TKey, TValue>>());
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(keyedItem2, key1));
+ string expectedParamName = collectionSize < 32 || generateKeyedItem.Name != KeyedCollectionTests<TKey, TValue>.GetNeverNullKeyMethod.Name ? "key" : null;
+ AssertExtensions.Throws<ArgumentException>(expectedParamName, null, () => collection.MyChangeItemKey(keyedItem2, key1));
collection.Verify(keys, items, itemsWithKeys);
}
ki => ki.Key != null)
.ToArray
<IKeyedItem<TKey, TValue>>());
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(keyedItem3, key3));
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(keyedItem3, key2));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(keyedItem3, key3));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(keyedItem3, key2));
var tempKeyedItem = new KeyedItem<TKey, TValue>(key1, item2);
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(tempKeyedItem, key2));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(tempKeyedItem, key2));
collection.Verify(keys, items, itemsWithKeys);
}
out items,
out itemsWithKeys);
collection.Add(item1);
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(default(TValue), key2));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(default(TValue), key2));
collection.Verify(
keys.Push(key1),
items.Push(item1),
keyedItem2.Key = key3;
if (collectionSize >= 32)
{
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(keyedItem2, key3));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(keyedItem2, key3));
}
else
{
keyedItem2.Key = key3;
if (collectionSize >= 32)
{
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(keyedItem2, key2));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(keyedItem2, key2));
}
else
{
keyedItem2.Key = key3;
if (collectionSize >= 32)
{
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(keyedItem2, key4));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(keyedItem2, key4));
}
else
{
tempKeyedItem.Key = key3;
if (collectionSize >= 32)
{
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(tempKeyedItem, key3));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(tempKeyedItem, key3));
}
else
{
tempKeyedItem.Key = key3;
if (collectionSize >= 32)
{
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(tempKeyedItem, default(TKey)));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(tempKeyedItem, default(TKey)));
}
else
{
tempKeyedItem.Key = key3;
if (collectionSize >= 32)
{
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(tempKeyedItem, key4));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(tempKeyedItem, key4));
}
else
{
keyedItem2.Key = default(TKey);
if (collectionSize >= 32 && keyedItem2.Key != null)
{
- AssertExtensions.Throws<ArgumentException>(null, () => collection.MyChangeItemKey(keyedItem2, key4));
+ AssertExtensions.Throws<ArgumentException>("item", null, () => collection.MyChangeItemKey(keyedItem2, key4));
}
else
{
out itemsWithKeys);
if (s_keyNullable)
{
- Assert.Throws<ArgumentNullException>(
- () => collection.Contains(default(TKey)));
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.Contains(default(TKey)));
}
else
{
TKey keyNotIn = itemNotIn.Key;
if (keyNotIn == null)
{
- Assert.Throws<ArgumentNullException>(
- () => collection.Contains(keyNotIn));
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.Contains(keyNotIn));
}
else
{
TKey key = k;
if (key == null)
{
- Assert.Throws<ArgumentNullException>(
- () => collection.Contains(key));
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.Contains(key));
continue;
}
Assert.True(collection.Contains(key));
TKey keyNotIn = itemNotIn.Key;
if (keyNotIn == null)
{
- Assert.Throws<ArgumentNullException>(
- () => collection.Remove(keyNotIn));
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.Remove(keyNotIn));
}
else
{
TKey key = keys[i];
if (key == null)
{
- Assert.Throws<ArgumentNullException>(
- () => collection.Remove(key));
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.Remove(key));
}
else
{
TKey keyNotIn = itemNotIn.Key;
if (keyNotIn == null)
{
- Assert.Throws<ArgumentNullException>(
- () => collection[keyNotIn]);
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection[keyNotIn]);
}
else
{
TKey key = k;
if (key == null)
{
- Assert.Throws<ArgumentNullException>(
- () => collection[key]);
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection[key]);
continue;
}
IKeyedItem<TKey, TValue> tmp = collection[key];
items = items.Push(keyedItem1);
itemsWithKeys = itemsWithKeys.Push(keyedItem1);
insert(collection, collection.Count, keyedItem1);
- AssertExtensions.Throws<ArgumentException>(null, () => insert(collection, collection.Count, tempKeyedItem));
+ string expectedParamName = collectionSize < 32 || generateKeyedItem.Name != KeyedCollectionTests<TKey, TValue>.GetNeverNullKeyMethod.Name ? "key" : null;
+ AssertExtensions.Throws<ArgumentException>(expectedParamName, null, () => insert(collection, collection.Count, tempKeyedItem));
collection.Verify(keys, items, itemsWithKeys);
}
if (keyNotIn == null)
{
IKeyedItem<TKey, TValue> item;
- Assert.Throws<ArgumentNullException>(
- () => collection.TryGetValue(keyNotIn, out item));
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(keyNotIn, out item));
}
else
{
TKey key = k;
if (key == null)
{
- Assert.Throws<ArgumentNullException>(
- () => collection.TryGetValue(key, out item));
+ AssertExtensions.Throws<ArgumentNullException>("key", () => collection.TryGetValue(key, out item));
continue;
}
Assert.True(collection.TryGetValue(key, out item));
public static void ItemTestSet_Negative_InvalidIndex(int size, int index)
{
var col = new ObservableCollection<int>(new int[size]);
- Assert.Throws<ArgumentOutOfRangeException>(() => col[index]);
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => col[index]);
}
// ICollection<T>.IsReadOnly
Assert.Equal(0, col.Count);
Assert.Empty(col);
- Assert.Throws<ArgumentOutOfRangeException>(() => col[1]);
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => col[1]);
//tests that the collectionChanged events are fired.
CollectionAndPropertyChangedTester helper = new CollectionAndPropertyChangedTester();
int[] iArrInvalidValues = new int[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, int.MinValue };
foreach (var index in iArrInvalidValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.RemoveAt(index));
Assert.Equal(anArray.Length, collection.Count);
}
int[] iArrLargeValues = new int[] { collection.Count, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 };
foreach (var index in iArrLargeValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.RemoveAt(index));
Assert.Equal(anArray.Length, collection.Count);
}
}
collection.CollectionChanged += (o, e) => { throw new ShouldNotBeInvokedException(); };
// invalid startIndex, valid destination index.
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Move(index, validIndex));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Move(index, validIndex));
Assert.Equal(anArray.Length, collection.Count);
// valid startIndex, invalid destIndex.
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Move(validIndex, index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Move(validIndex, index));
//NOTE: It actually moves the item right out of the collection.So the count is one less.
//Assert.Equal(anArray.Length, collection.Count, "Collection should not have changed. index: " + index);
}
collection.CollectionChanged += (o, e) => { throw new ShouldNotBeInvokedException(); };
// invalid startIndex, valid destination index.
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Move(index, validIndex));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Move(index, validIndex));
Assert.Equal(anArray.Length, collection.Count);
// valid startIndex, invalid destIndex.
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Move(validIndex, index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Move(validIndex, index));
//NOTE: It actually moves the item right out of the collection. So the count is one less.
//Assert.Equal(anArray.Length, collection.Count, "Collection should not have changed.");
}
int[] iArrInvalidValues = new int[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, int.MinValue };
foreach (var index in iArrInvalidValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(index, itemToInsert));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Insert(index, itemToInsert));
Assert.Equal(anArray.Length, collection.Count);
}
int[] iArrLargeValues = new int[] { collection.Count + 1, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 };
foreach (var index in iArrLargeValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(index, itemToInsert));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Insert(index, itemToInsert));
Assert.Equal(anArray.Length, collection.Count);
}
}
foreach (var index in iArrInvalidValues)
{
string[] aCopy = new string[collection.Count];
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.CopyTo(aCopy, index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("destinationIndex", "dstIndex", () => collection.CopyTo(aCopy, index));
}
int[] iArrLargeValues = new int[] { collection.Count, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 };
AssertExtensions.Throws<ArgumentException>("destinationArray", null, () => collection.CopyTo(aCopy, index));
}
- Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null, 1));
+ AssertExtensions.Throws<ArgumentNullException>("destinationArray", "dest", () => collection.CopyTo(null, 1));
string[] copy = new string[collection.Count - 1];
AssertExtensions.Throws<ArgumentException>("destinationArray", "", () => collection.CopyTo(copy, 0));
[Fact]
public static void CtorTests_Negative()
{
- Assert.Throws<ArgumentNullException>(() => { ReadOnlyDictionary<int, string> dict = new ReadOnlyDictionary<int, string>(null); });
+ AssertExtensions.Throws<ArgumentNullException>("dictionary", () => new ReadOnlyDictionary<int, string>(null));
}
/// <summary>
[Fact]
public static void Ctor_Tests_Negative()
{
- ReadOnlyObservableCollection<string> collection;
- Assert.Throws<ArgumentNullException>(() => collection = new ReadOnlyObservableCollection<string>(null));
+ AssertExtensions.Throws<ArgumentNullException>("list", () => new ReadOnlyObservableCollection<string>(null));
}
[Fact]
foreach (var index in iArrInvalidValues)
{
string[] aCopy = new string[anArray.Length];
- Assert.Throws<ArgumentOutOfRangeException>(() => readOnlyCol.CopyTo(aCopy, index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("destinationIndex", "dstIndex", () => readOnlyCol.CopyTo(aCopy, index));
}
int[] iArrLargeValues = new int[] { anArray.Length, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 };
AssertExtensions.Throws<ArgumentException>("destinationArray", null, () => readOnlyCol.CopyTo(aCopy, index));
}
- Assert.Throws<ArgumentNullException>(() => readOnlyCol.CopyTo(null, 1));
+ AssertExtensions.Throws<ArgumentNullException>("destinationArray", "dest", () => readOnlyCol.CopyTo(null, 1));
string[] copy = new string[anArray.Length - 1];
AssertExtensions.Throws<ArgumentException>("destinationArray", "", () => readOnlyCol.CopyTo(copy, 0));
public void Item_get_Tests_Negative()
{
// Verify get_Item with index=Int32.MinValue
- Assert.Throws<ArgumentOutOfRangeException>(() => { T item = _collection[int.MinValue]; });
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => _collection[int.MinValue]);
// Verify that the collection was not mutated
VerifyReadOnlyCollection(_collection, _expectedItems);
// Verify get_Item with index=-1
- Assert.Throws<ArgumentOutOfRangeException>(() => { T item = _collection[-1]; });
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => _collection[-1]);
// Verify that the collection was not mutated
VerifyReadOnlyCollection(_collection, _expectedItems);
if (_expectedItems.Length == 0)
{
// Verify get_Item with index=0 on Empty collection
- Assert.Throws<ArgumentOutOfRangeException>(() => { T item = _collection[0]; });
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => _collection[0]);
// Verify that the collection was not mutated
VerifyReadOnlyCollection(_collection, _expectedItems);
else
{
// Verify get_Item with index=Count on Empty collection
- Assert.Throws<ArgumentOutOfRangeException>(() => { T item = _collection[_expectedItems.Length]; });
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => _collection[_expectedItems.Length]);
// Verify that the collection was not mutated
VerifyReadOnlyCollection(_collection, _expectedItems);
int[] iArrInvalidValues = new int[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, int.MinValue };
foreach (var index in iArrInvalidValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.RemoveAt(index));
Assert.Equal(anArray.Length, readonlyCol.Count);
}
int[] iArrLargeValues = new int[] { collection.Count, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 };
foreach (var index in iArrLargeValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt(index));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.RemoveAt(index));
Assert.Equal(anArray.Length, readonlyCol.Count);
}
}
foreach (var index in iArrInvalidValues)
{
// invalid startIndex, valid destination index.
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Move(index, validIndex));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Move(index, validIndex));
Assert.Equal(anArray.Length, collection.Count);
}
foreach (var index in iArrLargeValues)
{
// invalid startIndex, valid destination index.
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Move(index, validIndex));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Move(index, validIndex));
Assert.Equal(anArray.Length, collection.Count);
}
}
int[] iArrInvalidValues = new int[] { -1, -2, -100, -1000, -10000, -100000, -1000000, -10000000, -100000000, -1000000000, int.MinValue };
foreach (var index in iArrInvalidValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(index, itemToInsert));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Insert(index, itemToInsert));
Assert.Equal(anArray.Length, collection.Count);
}
int[] iArrLargeValues = new int[] { collection.Count + 1, int.MaxValue, int.MaxValue / 2, int.MaxValue / 10 };
foreach (var index in iArrLargeValues)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(index, itemToInsert));
+ AssertExtensions.Throws<ArgumentOutOfRangeException>("index", () => collection.Insert(index, itemToInsert));
Assert.Equal(anArray.Length, collection.Count);
}
}
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework has a bug and throws NRE")]
public void Ctor_NullTypeNetCore_ThrowsArgumentNullException()
{
- Assert.Throws<ArgumentNullException>("type", () => new TypeConverterAttribute((Type)null));
+ AssertExtensions.Throws<ArgumentNullException>("type", () => new TypeConverterAttribute((Type)null));
}
[Fact]