Class CollectionHelpers
- Namespace
- PolyType.SourceGenModel
- Assembly
- PolyType.dll
Collection helper methods to be consumed by the source generator.
public static class CollectionHelpers
- Inheritance
-
CollectionHelpers
- Inherited Members
Methods
AsReadOnlyDictionary<TDictionary>(TDictionary)
Creates a IReadOnlyDictionary<TKey, TValue> adapter for a IDictionary.
public static IReadOnlyDictionary<object, object?> AsReadOnlyDictionary<TDictionary>(TDictionary dictionary) where TDictionary : IDictionary
Parameters
dictionary
TDictionaryThe source dictionary to be wrapped.
Returns
- IReadOnlyDictionary<object, object>
A read-only dictionary instance wrapping the source dictionary.
Type Parameters
TDictionary
The dictionary type to be wrapped.
AsReadOnlyDictionary<TDictionary, TKey, TValue>(TDictionary)
Creates a IReadOnlyDictionary<TKey, TValue> adapter for a IDictionary<TKey, TValue>.
public static IReadOnlyDictionary<TKey, TValue> AsReadOnlyDictionary<TDictionary, TKey, TValue>(TDictionary dictionary) where TDictionary : IDictionary<TKey, TValue>
Parameters
dictionary
TDictionaryThe source dictionary to be wrapped.
Returns
- IReadOnlyDictionary<TKey, TValue>
A read-only dictionary instance wrapping the source dictionary.
Type Parameters
TDictionary
The dictionary type to be wrapped.
TKey
The key type of the dictionary.
TValue
The value type of the dictionary.
CreateDictionary<TKey, TValue>(ReadOnlySpan<KeyValuePair<TKey, TValue>>)
Creates a dictionary from a span of key/value pairs.
public static Dictionary<TKey, TValue> CreateDictionary<TKey, TValue>(ReadOnlySpan<KeyValuePair<TKey, TValue>> span) where TKey : notnull
Parameters
span
ReadOnlySpan<KeyValuePair<TKey, TValue>>The span containing the entries of the dictionary.
Returns
- Dictionary<TKey, TValue>
A new dictionary containing the specified entries.
Type Parameters
TKey
The key type of the dictionary.
TValue
The value type of the dictionary.
CreateHashSet<T>(ReadOnlySpan<T>)
Creates a set from a ReadOnlySpan<T>.
public static HashSet<T> CreateHashSet<T>(ReadOnlySpan<T> span)
Parameters
span
ReadOnlySpan<T>The span containing the elements of the set.
Returns
- HashSet<T>
A new set containing the specified elements.
Type Parameters
T
The element type of the set.
CreateList<T>(ReadOnlySpan<T>)
Creates a list from a ReadOnlySpan<T>.
public static List<T> CreateList<T>(ReadOnlySpan<T> span)
Parameters
span
ReadOnlySpan<T>The span containing the elements of the list.
Returns
- List<T>
A new list containing the specified elements.
Type Parameters
T
The element type of the list.