Table of Contents

Class DictionaryResultExtensions

Namespace
Olve.Results
Assembly
Olve.Results.dll

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

dictionary IReadOnlyDictionary<TKey, TValue>

The dictionary to look up.

key TKey

The 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

TKey

The type of keys in the dictionary.

TValue

The 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

dictionary IDictionary<TKey, TValue>

The dictionary to add to.

key TKey

The key to add.

value TValue

The value to add.

Returns

Result

A successful result if the key was added; a failure if the key already exists.

Type Parameters

TKey

The type of keys in the dictionary.

TValue

The type of values in the dictionary.