Skip to content

Commit c6a3984

Browse files
authored
Document exceptions in OrderedDictionary (#113091)
* Document exceptions in OrderedDictionary * tweak SetAt param doc
1 parent eb30fcf commit c6a3984

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public OrderedDictionary(IEqualityComparer<TKey>? comparer) : this(0, comparer)
9797
/// The <see cref="IEqualityComparer{TKey}"/> implementation to use when comparing keys,
9898
/// or null to use the default <see cref="EqualityComparer{TKey}"/> for the type of the key.
9999
/// </param>
100-
/// <exception cref="ArgumentOutOfRangeException">capacity is less than 0.</exception>
100+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
101101
public OrderedDictionary(int capacity, IEqualityComparer<TKey>? comparer)
102102
{
103103
ThrowIfNegative(capacity);
@@ -145,7 +145,7 @@ public OrderedDictionary(int capacity, IEqualityComparer<TKey>? comparer)
145145
/// The <see cref="IDictionary{TKey, TValue}"/> whose elements are copied to the new <see cref="OrderedDictionary{TKey, TValue}"/>.
146146
/// The initial order of the elements in the new collection is the order the elements are enumerated from the supplied dictionary.
147147
/// </param>
148-
/// <exception cref="ArgumentNullException"><paramref name="dictionary"/> is null.</exception>
148+
/// <exception cref="ArgumentNullException"><paramref name="dictionary"/> is <see langword="null"/>.</exception>
149149
public OrderedDictionary(IDictionary<TKey, TValue> dictionary) : this(dictionary, null)
150150
{
151151
}
@@ -162,7 +162,7 @@ public OrderedDictionary(IDictionary<TKey, TValue> dictionary) : this(dictionary
162162
/// The <see cref="IEqualityComparer{TKey}"/> implementation to use when comparing keys,
163163
/// or null to use the default <see cref="EqualityComparer{TKey}"/> for the type of the key.
164164
/// </param>
165-
/// <exception cref="ArgumentNullException"><paramref name="dictionary"/> is null.</exception>
165+
/// <exception cref="ArgumentNullException"><paramref name="dictionary"/> is <see langword="null"/>.</exception>
166166
public OrderedDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey>? comparer) :
167167
this(dictionary?.Count ?? 0, comparer)
168168
{
@@ -179,7 +179,7 @@ public OrderedDictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer
179179
/// The <see cref="IEnumerable{T}"/> whose elements are copied to the new <see cref="OrderedDictionary{TKey, TValue}"/>.
180180
/// The initial order of the elements in the new collection is the order the elements are enumerated from the supplied collection.
181181
/// </param>
182-
/// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>
182+
/// <exception cref="ArgumentNullException"><paramref name="collection"/> is <see langword="null"/>.</exception>
183183
public OrderedDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection) : this(collection, null)
184184
{
185185
}
@@ -196,7 +196,7 @@ public OrderedDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection) : t
196196
/// The <see cref="IEqualityComparer{TKey}"/> implementation to use when comparing keys,
197197
/// or null to use the default <see cref="EqualityComparer{TKey}"/> for the type of the key.
198198
/// </param>
199-
/// <exception cref="ArgumentNullException"><paramref name="collection"/> is null.</exception>
199+
/// <exception cref="ArgumentNullException"><paramref name="collection"/> is <see langword="null"/>.</exception>
200200
public OrderedDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey>? comparer) :
201201
this((collection as ICollection<KeyValuePair<TKey, TValue>>)?.Count ?? 0, comparer)
202202
{
@@ -359,7 +359,7 @@ KeyValuePair<TKey, TValue> IList<KeyValuePair<TKey, TValue>>.this[int index]
359359
/// <summary>Gets or sets the value associated with the specified key.</summary>
360360
/// <param name="key">The key of the value to get or set.</param>
361361
/// <returns>The value associated with the specified key. If the specified key is not found, a get operation throws a <see cref="KeyNotFoundException"/>, and a set operation creates a new element with the specified key.</returns>
362-
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
362+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
363363
/// <exception cref="KeyNotFoundException">The property is retrieved and <paramref name="key"/> does not exist in the collection.</exception>
364364
/// <remarks>Setting the value of an existing key does not impact its order in the collection.</remarks>
365365
public TValue this[TKey key]
@@ -479,8 +479,8 @@ private bool TryInsert(int index, TKey key, TValue value, InsertionBehavior beha
479479

480480
/// <summary>Adds the specified key and value to the dictionary.</summary>
481481
/// <param name="key">The key of the element to add.</param>
482-
/// <param name="value">The value of the element to add. The value can be null for reference types.</param>
483-
/// <exception cref="ArgumentNullException">key is null.</exception>
482+
/// <param name="value">The value of the element to add. The value can be <see langword="null"/> for reference types.</param>
483+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
484484
/// <exception cref="ArgumentException">An element with the same key already exists in the <see cref="OrderedDictionary{TKey, TValue}"/>.</exception>
485485
public void Add(TKey key, TValue value)
486486
{
@@ -491,17 +491,17 @@ public void Add(TKey key, TValue value)
491491

492492
/// <summary>Adds the specified key and value to the dictionary if the key doesn't already exist.</summary>
493493
/// <param name="key">The key of the element to add.</param>
494-
/// <param name="value">The value of the element to add. The value can be null for reference types.</param>
495-
/// <exception cref="ArgumentNullException">key is null.</exception>
496-
/// <returns>true if the key didn't exist and the key and value were added to the dictionary; otherwise, false.</returns>
494+
/// <param name="value">The value of the element to add. The value can be <see langword="null"/> for reference types.</param>
495+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
496+
/// <returns><see langword="true"/> if the key didn't exist and the key and value were added to the dictionary; otherwise, <see langword="false"/>.</returns>
497497
public bool TryAdd(TKey key, TValue value) => TryAdd(key, value, out _);
498498

499499
/// <summary>Adds the specified key and value to the dictionary if the key doesn't already exist.</summary>
500500
/// <param name="key">The key of the element to add.</param>
501-
/// <param name="value">The value of the element to add. The value can be null for reference types.</param>
501+
/// <param name="value">The value of the element to add. The value can be <see langword="null"/> for reference types.</param>
502502
/// <param name="index">The index of the added or existing <paramref name="key"/>. This is always a valid index into the dictionary.</param>
503-
/// <exception cref="ArgumentNullException">key is null.</exception>
504-
/// <returns>true if the key didn't exist and the key and value were added to the dictionary; otherwise, false.</returns>
503+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
504+
/// <returns><see langword="true"/> if the key didn't exist and the key and value were added to the dictionary; otherwise, <see langword="false"/>.</returns>
505505
public bool TryAdd(TKey key, TValue value, out int index)
506506
{
507507
ThrowIfNull(key);
@@ -546,12 +546,13 @@ public void Clear()
546546

547547
/// <summary>Determines whether the <see cref="OrderedDictionary{TKey, TValue}"/> contains the specified key.</summary>
548548
/// <param name="key">The key to locate in the <see cref="OrderedDictionary{TKey, TValue}"/>.</param>
549-
/// <returns>true if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, false.</returns>
549+
/// <returns><see langword="true"/> if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, <see langword="false"/>.</returns>
550+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
550551
public bool ContainsKey(TKey key) => IndexOf(key) >= 0;
551552

552553
/// <summary>Determines whether the <see cref="OrderedDictionary{TKey, TValue}"/> contains a specific value.</summary>
553554
/// <param name="value">The value to locate in the <see cref="OrderedDictionary{TKey, TValue}"/>. The value can be null for reference types.</param>
554-
/// <returns>true if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified value; otherwise, false.</returns>
555+
/// <returns><see langword="true"/> if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified value; otherwise, <see langword="false"/>.</returns>
555556
public bool ContainsValue(TValue value)
556557
{
557558
int count = _count;
@@ -607,7 +608,7 @@ public KeyValuePair<TKey, TValue> GetAt(int index)
607608
/// <summary>Determines the index of a specific key in the <see cref="OrderedDictionary{TKey, TValue}"/>.</summary>
608609
/// <param name="key">The key to locate.</param>
609610
/// <returns>The index of <paramref name="key"/> if found; otherwise, -1.</returns>
610-
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
611+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
611612
public int IndexOf(TKey key)
612613
{
613614
ThrowIfNull(key);
@@ -717,7 +718,7 @@ private int IndexOf(TKey key, ref uint outHashCode, ref uint outCollisionCount)
717718
/// <param name="index">The zero-based index at which item should be inserted.</param>
718719
/// <param name="key">The key to insert.</param>
719720
/// <param name="value">The value to insert.</param>
720-
/// <exception cref="ArgumentNullException">key is null.</exception>
721+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
721722
/// <exception cref="ArgumentException">An element with the same key already exists in the <see cref="OrderedDictionary{TKey, TValue}"/>.</exception>
722723
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than <see cref="Count"/>.</exception>
723724
public void Insert(int index, TKey key, TValue value)
@@ -734,13 +735,15 @@ public void Insert(int index, TKey key, TValue value)
734735

735736
/// <summary>Removes the value with the specified key from the <see cref="OrderedDictionary{TKey, TValue}"/>.</summary>
736737
/// <param name="key">The key of the element to remove.</param>
737-
/// <returns></returns>
738+
/// <returns><see langword="true"/> if the element is successfully found and removed; otherwise, <see langword="false"/>.</returns>
739+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
738740
public bool Remove(TKey key) => Remove(key, out _);
739741

740742
/// <summary>Removes the value with the specified key from the <see cref="OrderedDictionary{TKey, TValue}"/> and copies the element to the value parameter.</summary>
741743
/// <param name="key">The key of the element to remove.</param>
742744
/// <param name="value">The removed element.</param>
743-
/// <returns>true if the element is successfully found and removed; otherwise, false.</returns>
745+
/// <returns><see langword="true"/> if the element is successfully found and removed; otherwise, <see langword="false"/>.</returns>
746+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
744747
public bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value)
745748
{
746749
ThrowIfNull(key);
@@ -764,6 +767,7 @@ public bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value)
764767

765768
/// <summary>Removes the key/value pair at the specified index.</summary>
766769
/// <param name="index">The zero-based index of the item to remove.</param>
770+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception>
767771
public void RemoveAt(int index)
768772
{
769773
int count = _count;
@@ -789,8 +793,9 @@ public void RemoveAt(int index)
789793
}
790794

791795
/// <summary>Sets the value for the key at the specified index.</summary>
792-
/// <param name="index">The zero-based index of the element to get or set.</param>
796+
/// <param name="index">The zero-based index at which to set the value.</param>
793797
/// <param name="value">The value to store at the specified index.</param>
798+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception>
794799
public void SetAt(int index, TValue value)
795800
{
796801
if ((uint)index >= (uint)_count)
@@ -804,10 +809,12 @@ public void SetAt(int index, TValue value)
804809
}
805810

806811
/// <summary>Sets the key/value pair at the specified index.</summary>
807-
/// <param name="index">The zero-based index of the element to get or set.</param>
812+
/// <param name="index">The zero-based index at which to set the key/value pair.</param>
808813
/// <param name="key">The key to store at the specified index.</param>
809814
/// <param name="value">The value to store at the specified index.</param>
810-
/// <exception cref="ArgumentException"></exception>
815+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
816+
/// <exception cref="ArgumentException">An element with the same key already exists at an index different to <paramref name="index"/>.</exception>
817+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception>
811818
public void SetAt(int index, TKey key, TValue value)
812819
{
813820
if ((uint)index >= (uint)_count)
@@ -910,7 +917,8 @@ public void TrimExcess(int capacity)
910917
/// When this method returns, contains the value associated with the specified key, if the key is found;
911918
/// otherwise, the default value for the type of the value parameter.
912919
/// </param>
913-
/// <returns>true if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, false.</returns>
920+
/// <returns><see langword="true"/> if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, <see langword="false"/>.</returns>
921+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
914922
public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) => TryGetValue(key, out value, out _);
915923

916924
/// <summary>Gets the value associated with the specified key.</summary>
@@ -920,7 +928,8 @@ public void TrimExcess(int capacity)
920928
/// otherwise, the default value for the type of the value parameter.
921929
/// </param>
922930
/// <param name="index">The index of <paramref name="key"/> if found; otherwise, -1.</param>
923-
/// <returns>true if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, false.</returns>
931+
/// <returns><see langword="true"/> if the <see cref="OrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, <see langword="false"/>.</returns>
932+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
924933
public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value, out int index)
925934
{
926935
ThrowIfNull(key);

0 commit comments

Comments
 (0)