Class DictionaryResultExtensions
Extension methods for dictionary operations that return Result instead of throwing.
public static class DictionaryResultExtensions
- Inheritance
-
DictionaryResultExtensions
- Inherited Members
Methods
GetWithResult<TKey, TValue>(IReadOnlyDictionary<TKey, TValue>, TKey)
Attempts to retrieve the value associated with the specified key, returning a Result<T>.
public static Result<TValue> GetWithResult<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
Parameters
dictionaryIReadOnlyDictionary<TKey, TValue>The dictionary to look up.
keyTKeyThe key to look up.
Returns
- Result<TValue>
A successful result with the value if the key was found; a failure if the key was not found.
Type Parameters
TKeyThe type of keys in the dictionary.
TValueThe type of values in the dictionary.
SetWithResult<TKey, TValue>(IDictionary<TKey, TValue>, TKey, TValue)
Attempts to add a key-value pair to the dictionary, returning a Result indicating success or failure.
public static Result SetWithResult<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value) where TKey : notnull
Parameters
dictionaryIDictionary<TKey, TValue>The dictionary to add to.
keyTKeyThe key to add.
valueTValueThe value to add.
Returns
- Result
A successful result if the key was added; a failure if the key already exists.
Type Parameters
TKeyThe type of keys in the dictionary.
TValueThe type of values in the dictionary.