|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics.CodeAnalysis; |
| 4 | + |
| 5 | +namespace Renci.SshNet |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// Represents a collection of key/value pairs that are accessible by the key or index. |
| 9 | + /// </summary> |
| 10 | + /// <typeparam name="TKey">The type of the keys in the dictionary.</typeparam> |
| 11 | + /// <typeparam name="TValue">The type of the values in the dictionary.</typeparam> |
| 12 | + public interface IOrderedDictionary<TKey, TValue> : |
| 13 | + IDictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue> |
| 14 | + where TKey : notnull |
| 15 | + { |
| 16 | + // Some members are redefined with 'new' to resolve ambiguities. |
| 17 | + |
| 18 | + /// <summary>Gets or sets the value associated with the specified key.</summary> |
| 19 | + /// <param name="key">The key of the value to get or set.</param> |
| 20 | + /// <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> |
| 21 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 22 | + /// <exception cref="KeyNotFoundException">The property is retrieved and <paramref name="key"/> does not exist in the collection.</exception> |
| 23 | + /// <remarks>Setting the value of an existing key does not impact its order in the collection.</remarks> |
| 24 | + new TValue this[TKey key] { get; set; } |
| 25 | + |
| 26 | + /// <summary>Gets a collection containing the keys in the <see cref="IOrderedDictionary{TKey, TValue}"/>.</summary> |
| 27 | + new ICollection<TKey> Keys { get; } |
| 28 | + |
| 29 | + /// <summary>Gets a collection containing the values in the <see cref="IOrderedDictionary{TKey, TValue}"/>.</summary> |
| 30 | + new ICollection<TValue> Values { get; } |
| 31 | + |
| 32 | + /// <summary>Gets the number of key/value pairs contained in the <see cref="IOrderedDictionary{TKey, TValue}"/>.</summary> |
| 33 | + new int Count { get; } |
| 34 | + |
| 35 | + /// <summary>Determines whether the <see cref="IOrderedDictionary{TKey, TValue}"/> contains the specified key.</summary> |
| 36 | + /// <param name="key">The key to locate in the <see cref="IOrderedDictionary{TKey, TValue}"/>.</param> |
| 37 | + /// <returns><see langword="true"/> if the <see cref="IOrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, <see langword="false"/>.</returns> |
| 38 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 39 | + new bool ContainsKey(TKey key); |
| 40 | + |
| 41 | + /// <summary>Determines whether the <see cref="IOrderedDictionary{TKey, TValue}"/> contains a specific value.</summary> |
| 42 | + /// <param name="value">The value to locate in the <see cref="IOrderedDictionary{TKey, TValue}"/>. The value can be null for reference types.</param> |
| 43 | + /// <returns><see langword="true"/> if the <see cref="IOrderedDictionary{TKey, TValue}"/> contains an element with the specified value; otherwise, <see langword="false"/>.</returns> |
| 44 | + bool ContainsValue(TValue value); |
| 45 | + |
| 46 | + /// <summary>Gets the key/value pair at the specified index.</summary> |
| 47 | + /// <param name="index">The zero-based index of the pair to get.</param> |
| 48 | + /// <returns>The element at the specified index.</returns> |
| 49 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception> |
| 50 | + KeyValuePair<TKey, TValue> GetAt(int index); |
| 51 | + |
| 52 | + /// <summary>Determines the index of a specific key in the <see cref="IOrderedDictionary{TKey, TValue}"/>.</summary> |
| 53 | + /// <param name="key">The key to locate.</param> |
| 54 | + /// <returns>The index of <paramref name="key"/> if found; otherwise, -1.</returns> |
| 55 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 56 | + int IndexOf(TKey key); |
| 57 | + |
| 58 | + /// <summary>Inserts an item into the collection at the specified index.</summary> |
| 59 | + /// <param name="index">The zero-based index at which item should be inserted.</param> |
| 60 | + /// <param name="key">The key to insert.</param> |
| 61 | + /// <param name="value">The value to insert.</param> |
| 62 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 63 | + /// <exception cref="ArgumentException">An element with the same key already exists in the <see cref="IOrderedDictionary{TKey, TValue}"/>.</exception> |
| 64 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than <see cref="Count"/>.</exception> |
| 65 | + void Insert(int index, TKey key, TValue value); |
| 66 | + |
| 67 | + /// <summary>Removes the value with the specified key from the <see cref="IOrderedDictionary{TKey, TValue}"/> and copies the element to the value parameter.</summary> |
| 68 | + /// <param name="key">The key of the element to remove.</param> |
| 69 | + /// <param name="value">The removed element.</param> |
| 70 | + /// <returns><see langword="true"/> if the element is successfully found and removed; otherwise, <see langword="false"/>.</returns> |
| 71 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 72 | + bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value); |
| 73 | + |
| 74 | + /// <summary>Removes the key/value pair at the specified index.</summary> |
| 75 | + /// <param name="index">The zero-based index of the item to remove.</param> |
| 76 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception> |
| 77 | + void RemoveAt(int index); |
| 78 | + |
| 79 | + /// <summary>Sets the key/value pair at the specified index.</summary> |
| 80 | + /// <param name="index">The zero-based index at which to set the key/value pair.</param> |
| 81 | + /// <param name="key">The key to store at the specified index.</param> |
| 82 | + /// <param name="value">The value to store at the specified index.</param> |
| 83 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 84 | + /// <exception cref="ArgumentException">An element with the same key already exists at an index different to <paramref name="index"/>.</exception> |
| 85 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception> |
| 86 | + void SetAt(int index, TKey key, TValue value); |
| 87 | + |
| 88 | + /// <summary>Sets the value for the key at the specified index.</summary> |
| 89 | + /// <param name="index">The zero-based index at which to set the key/value pair.</param> |
| 90 | + /// <param name="value">The value to store at the specified index.</param> |
| 91 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception> |
| 92 | + void SetAt(int index, TValue value); |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Moves an existing key/value pair to the specified index in the collection. |
| 96 | + /// </summary> |
| 97 | + /// <param name="index">The current zero-based index of the key/value pair to move.</param> |
| 98 | + /// <param name="newIndex">The zero-based index at which to set the key/value pair.</param> |
| 99 | + /// <exception cref="ArgumentOutOfRangeException"> |
| 100 | + /// <paramref name="index"/> or <paramref name="newIndex"/> are less than 0 or greater than or equal to <see cref="Count"/>. |
| 101 | + /// </exception> |
| 102 | + void SetPosition(int index, int newIndex); |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Moves an existing key/value pair to the specified index in the collection. |
| 106 | + /// </summary> |
| 107 | + /// <param name="key">The key to move.</param> |
| 108 | + /// <param name="newIndex">The zero-based index at which to set the key/value pair.</param> |
| 109 | + /// <exception cref="KeyNotFoundException">The specified key does not exist in the collection.</exception> |
| 110 | + /// <exception cref="ArgumentOutOfRangeException"><paramref name="newIndex"/> is less than 0 or greater than or equal to <see cref="Count"/>.</exception> |
| 111 | + void SetPosition(TKey key, int newIndex); |
| 112 | + |
| 113 | + /// <summary>Adds the specified key and value to the dictionary if the key doesn't already exist.</summary> |
| 114 | + /// <param name="key">The key of the element to add.</param> |
| 115 | + /// <param name="value">The value of the element to add. The value can be <see langword="null"/> for reference types.</param> |
| 116 | + /// <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> |
| 117 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 118 | + bool TryAdd(TKey key, TValue value); |
| 119 | + |
| 120 | + /// <summary>Adds the specified key and value to the dictionary if the key doesn't already exist.</summary> |
| 121 | + /// <param name="key">The key of the element to add.</param> |
| 122 | + /// <param name="value">The value of the element to add. The value can be <see langword="null"/> for reference types.</param> |
| 123 | + /// <param name="index">The index of the added or existing <paramref name="key"/>. This is always a valid index into the dictionary.</param> |
| 124 | + /// <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> |
| 125 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 126 | + bool TryAdd(TKey key, TValue value, out int index); |
| 127 | + |
| 128 | + /// <summary>Gets the value associated with the specified key.</summary> |
| 129 | + /// <param name="key">The key of the value to get.</param> |
| 130 | + /// <param name="value"> |
| 131 | + /// When this method returns, contains the value associated with the specified key, if the key is found; |
| 132 | + /// otherwise, the default value for the type of the value parameter. |
| 133 | + /// </param> |
| 134 | + /// <returns><see langword="true"/> if the <see cref="IOrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, <see langword="false"/>.</returns> |
| 135 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 136 | + new bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value); |
| 137 | + |
| 138 | + /// <summary>Gets the value associated with the specified key.</summary> |
| 139 | + /// <param name="key">The key of the value to get.</param> |
| 140 | + /// <param name="value"> |
| 141 | + /// When this method returns, contains the value associated with the specified key, if the key is found; |
| 142 | + /// otherwise, the default value for the type of the value parameter. |
| 143 | + /// </param> |
| 144 | + /// <param name="index">The index of <paramref name="key"/> if found; otherwise, -1.</param> |
| 145 | + /// <returns><see langword="true"/> if the <see cref="IOrderedDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, <see langword="false"/>.</returns> |
| 146 | + /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| 147 | + bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value, out int index); |
| 148 | + } |
| 149 | +} |
0 commit comments