Skip to content

Commit 48554cd

Browse files
Checkpoint.
1 parent 1c07f3a commit 48554cd

11 files changed

Lines changed: 381 additions & 483 deletions

source/CollectionWrapper.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ protected virtual void AddInternal(T item)
2020
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2121
public virtual void Add(T item) => AddInternal(item);
2222

23-
/// <inheritdoc cref="ICollection&lt;T&gt;" />
23+
/// <summary>Adds more than one item.</summary>
2424
/// <param name="item1">First item to add.</param>
2525
/// <param name="item2">Additional item to add.</param>
2626
/// <param name="items">Extended param items to add.</param>
27-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
28-
public virtual void Add(T item1, T item2, params T[] items)
29-
{
30-
AddInternal(item1);
31-
AddInternal(item2);
32-
foreach (T? i in items)
33-
AddInternal(i);
34-
}
27+
public virtual void AddThese(T item1, T item2, params T[] items)
28+
{
29+
AddInternal(item1);
30+
AddInternal(item2);
31+
foreach (T? i in items)
32+
AddInternal(i);
33+
}
3534

3635
/// <summary>
3736
/// Adds mutliple items to the collection.

source/DictionaryWrapper.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace Open.Collections;
5+
6+
/// <inheritdoc />
7+
public class DictionaryWrapper<TKey, TValue>
8+
: CollectionWrapper<KeyValuePair<TKey, TValue>, IDictionary<TKey, TValue>>, IDictionary<TKey, TValue>
9+
{
10+
/// <inheritdoc />
11+
public DictionaryWrapper(int capacity = 0)
12+
: base(new Dictionary<TKey, TValue>(capacity))
13+
{
14+
}
15+
16+
/// <inheritdoc />
17+
public virtual TValue this[TKey key]
18+
{
19+
get => InternalSource[key];
20+
set => InternalSource[key] = value;
21+
}
22+
23+
/// <inheritdoc />
24+
public virtual ICollection<TKey> Keys
25+
=> InternalSource.Keys;
26+
27+
/// <inheritdoc />
28+
public virtual ICollection<TValue> Values
29+
=> InternalSource.Values;
30+
31+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
32+
/// <inheritdoc />
33+
public virtual void Add(TKey key, TValue value)
34+
=> InternalSource.Add(key, value);
35+
36+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37+
/// <inheritdoc />
38+
public bool ContainsKey(TKey key)
39+
=> InternalSource.ContainsKey(key);
40+
41+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
42+
/// <inheritdoc />
43+
public virtual bool Remove(TKey key)
44+
=> InternalSource.Remove(key);
45+
46+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47+
/// <inheritdoc />
48+
public bool TryGetValue(TKey key, out TValue value)
49+
=> InternalSource.TryGetValue(key, out value);
50+
}

source/IOrderedDictionary.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Open.Collections;
6+
7+
/// <summary>
8+
/// Represents a generic items of key/value pairs that are ordered independently of the key and value.
9+
/// </summary>
10+
/// <inheritdoc />
11+
public interface IOrderedDictionary<TKey, TValue> : IDictionary<TKey, TValue>
12+
{
13+
/// <summary>
14+
/// Adds an entry with the specified key and value into the <see cref="IOrderedDictionary{TKey,TValue}"/>.
15+
/// </summary>
16+
/// <returns>The index of the newly added entry</returns>
17+
/// <inheritdoc cref="Insert(int, TKey, TValue)"/>
18+
new int Add(TKey key, TValue value);
19+
20+
/// <summary>
21+
/// Inserts a new entry into the <see cref="IOrderedDictionary{TKey,TValue}"/> items with the specified key and value at the specified index.
22+
/// </summary>
23+
/// <param name="index">The zero-based index at which the element should be inserted.</param>
24+
/// <param name="key">The key of the entry to add.</param>
25+
/// <param name="value">The value of the entry to add. The value can be <see langword="null"/> if the type of the values in the dictionary is a reference type.</param>
26+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0.<br/>
27+
/// -or-<br/>
28+
/// <paramref name="index"/> is greater than <see cref="System.Collections.ICollection.Count"/>.</exception>
29+
/// <exception cref="ArgumentException">An element with the same key already exists in the <see cref="IOrderedDictionary{TKey,TValue}"/>.</exception>
30+
/// <exception cref="NotSupportedException">The <see cref="IOrderedDictionary{TKey,TValue}"/> is read-only.<br/>
31+
/// -or-<br/>
32+
/// The <see cref="IOrderedDictionary{TKey,TValue}"/> has a fized size.</exception>
33+
void Insert(int index, TKey key, TValue value);
34+
35+
/// <summary>
36+
/// Updates or creates and item.
37+
/// </summary>
38+
/// <returns>The index that was updated or added.</returns>
39+
int SetValue(TKey key, TValue value);
40+
41+
/// <summary>
42+
/// Returns the key at the requested <paramref name="index"/>.
43+
/// </summary>
44+
/// <exception cref="ArgumentOutOfRangeException">The index is less than zero or greater than the length of the collection.</exception>
45+
TKey GetKeyAt(int index);
46+
47+
/// <summary>
48+
/// Returns the value at the requested <paramref name="index"/>.
49+
/// </summary>
50+
/// <exception cref="ArgumentOutOfRangeException">The index is less than zero or greater than the length of the collection.</exception>
51+
TValue GetValueAt(int index);
52+
53+
/// <summary>
54+
/// Sets the <paramref name="value"/> of an item at the specified <paramref name="index"/>.
55+
/// </summary>
56+
/// <remarks><see langword="true"/> if the value changed; otherwise <see langword="false"/>.</remarks>
57+
/// <exception cref="ArgumentOutOfRangeException">The index is less than zero or greater than the length of the collection.</exception>
58+
bool SetValueAt(int index, TValue value);
59+
60+
/// <summary>
61+
/// Removes the entry at the specified index from the <see cref="IOrderedDictionary{TKey,TValue}"/> items.
62+
/// </summary>
63+
/// <param name="index">The zero-based index of the entry to remove.</param>
64+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than 0.<br/>
65+
/// -or-<br/>
66+
/// index is equal to or greater than <see cref="Count"/>.</exception>
67+
void RemoveAt(int index);
68+
}

0 commit comments

Comments
 (0)