Skip to content

,System.Func{--0,--1},System.Collections.Generic.IEqualityComparer{--1},System.Threading.CancellationToken)} ,System.Func{--0,--1})} ,System.Func{--0,--1},System.Func{--0,--2},System.Collections.Generic.IEqualityComparer{--1},System.Threading.CancellationToken)} ,System.Func{--0,--1},System.Func{--0,--2})}

ObservableAsync.ToDictionaryAsync(IObservableAsync, Func, IEqualityComparer?, CancellationToken) method

Defined in

Type: ObservableAsync Namespace: ReactiveUI.Extensions.Async Assembly: ReactiveUI.Extensions.dll

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481

Overloads

  • 1. public static ValueTask<Dictionary<TKey, T>> ToDictionaryAsync<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken) where TKey : notnull
  • 2. public static ValueTask<Dictionary<TKey, T>> ToDictionaryAsync<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector) where TKey : notnull
  • 3. public static ValueTask<Dictionary<TKey, TValue>> ToDictionaryAsync<T, TKey, TValue>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, Func<T, TValue> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken) where TKey : notnull
  • 4. public static ValueTask<Dictionary<TKey, TValue>> ToDictionaryAsync<T, TKey, TValue>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, Func<T, TValue> elementSelector) where TKey : notnull

1. Overload

public static ValueTask<Dictionary<TKey, T>> ToDictionaryAsync<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken) where TKey : notnull

Summary: Asynchronously creates a dictionary from the elements of the sequence, using the specified key selector function.

Type parameters

NameDescription
TThe type of elements in the source sequence.
TKeyThe type of the keys in the resulting dictionary. Must be non-nullable.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
keySelectorFuncA function to extract a key from each element in the sequence. Cannot be null.
comparerIEqualityComparer?An optional equality comparer to compare keys. If null, the default equality comparer for the key type is used.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.

Returns: ValueTask> -- A task that represents the asynchronous operation. The task result contains a dictionary mapping keys to elements from the sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown if the keySelector parameter is null.

2. Overload

public static ValueTask<Dictionary<TKey, T>> ToDictionaryAsync<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector) where TKey : notnull

View source

Summary: Asynchronously creates a dictionary from the elements of the sequence, using the specified key selector function and the default equality comparer for the key type.

Type parameters

NameDescription
TThe type of elements in the source sequence.
TKeyThe type of the keys in the resulting dictionary. Must be non-nullable.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
keySelectorFuncA function to extract a key from each element in the sequence. Cannot be null.

Returns: ValueTask> -- A task that represents the asynchronous operation. The task result contains a dictionary mapping keys to elements from the sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown if the keySelector parameter is null.

3. Overload

public static ValueTask<Dictionary<TKey, TValue>> ToDictionaryAsync<T, TKey, TValue>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, Func<T, TValue> elementSelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken) where TKey : notnull

Summary: Asynchronously creates a dictionary from the elements of the sequence using the specified key and element selector functions.

Type parameters

NameDescription
TThe type of elements in the source sequence.
TKeyThe type of the keys in the resulting dictionary. Must be non-nullable.
TValueThe type of the values in the resulting dictionary.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
keySelectorFuncA function to extract a key from each element in the sequence.
elementSelectorFuncA function to map each element in the sequence to a value in the resulting dictionary.
comparerIEqualityComparer?An optional equality comparer to compare keys. If null, the default equality comparer for the key type is used.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.

Returns: ValueTask> -- A task that represents the asynchronous operation. The task result contains a dictionary mapping keys to values as defined by the selector functions.

Remarks

If multiple elements produce the same key, an exception may be thrown. The operation is performed asynchronously and can be cancelled using the provided cancellation token.

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown if keySelector or elementSelector is null.

4. Overload

public static ValueTask<Dictionary<TKey, TValue>> ToDictionaryAsync<T, TKey, TValue>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, Func<T, TValue> elementSelector) where TKey : notnull

View source

Summary: Asynchronously creates a dictionary from the elements of the sequence using the specified key and element selector functions, with the default equality comparer for the key type.

Type parameters

NameDescription
TThe type of elements in the source sequence.
TKeyThe type of the keys in the resulting dictionary. Must be non-nullable.
TValueThe type of the values in the resulting dictionary.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
keySelectorFuncA function to extract a key from each element in the sequence.
elementSelectorFuncA function to map each element in the sequence to a value in the resulting dictionary.

Returns: ValueTask> -- A task that represents the asynchronous operation. The task result contains a dictionary mapping keys to values as defined by the selector functions.

Exceptions

TypeCondition
System.ArgumentNullExceptionThrown if keySelector or elementSelector is null.