Class JsonRpcExtensions
- Namespace
- StreamJsonRpc
- Assembly
- StreamJsonRpc.dll
Extension methods for use with JsonRpc.
public static class JsonRpcExtensions
- Inheritance
-
JsonRpcExtensions
- Inherited Members
Methods
AsAsyncEnumerable<T>(IEnumerable<T>)
Converts an IEnumerable<T> to IAsyncEnumerable<T> so it will be streamed over an RPC connection progressively instead of as an entire collection in one message.
public static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IEnumerable<T> enumerable)
Parameters
enumerable
IEnumerable<T>The enumerable to be converted.
Returns
- IAsyncEnumerable<T>
The async enumerable instance.
Type Parameters
T
The type of element enumerated by the sequence.
AsAsyncEnumerable<T>(IEnumerable<T>, JsonRpcEnumerableSettings?)
Converts an IEnumerable<T> to IAsyncEnumerable<T> so it will be streamed over an RPC connection progressively instead of as an entire collection in one message.
public static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IEnumerable<T> enumerable, JsonRpcEnumerableSettings? settings)
Parameters
enumerable
IEnumerable<T>The enumerable to be converted.
settings
JsonRpcEnumerableSettingsThe settings to associate with this enumerable.
Returns
- IAsyncEnumerable<T>
The async enumerable instance.
Type Parameters
T
The type of element enumerated by the sequence.
AsAsyncEnumerable<T>(IEnumerable<T>, JsonRpcEnumerableSettings?, CancellationToken)
Converts an IEnumerable<T> to IAsyncEnumerable<T> so it will be streamed over an RPC connection progressively instead of as an entire collection in one message.
public static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IEnumerable<T> enumerable, JsonRpcEnumerableSettings? settings, CancellationToken cancellationToken)
Parameters
enumerable
IEnumerable<T>The enumerable to be converted.
settings
JsonRpcEnumerableSettingsThe settings to associate with this enumerable.
cancellationToken
CancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
The async enumerable instance.
Type Parameters
T
The type of element enumerated by the sequence.
AsAsyncEnumerable<T>(IEnumerable<T>, CancellationToken)
Converts an IEnumerable<T> to IAsyncEnumerable<T> so it will be streamed over an RPC connection progressively instead of as an entire collection in one message.
public static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IEnumerable<T> enumerable, CancellationToken cancellationToken)
Parameters
enumerable
IEnumerable<T>The enumerable to be converted.
cancellationToken
CancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<T>
The async enumerable instance.
Type Parameters
T
The type of element enumerated by the sequence.
As<T>(IClientProxy)
Casts the proxy to the requested interface type, if it (intentionally) implements it.
public static T? As<T>(this IClientProxy proxy) where T : class
Parameters
proxy
IClientProxy
Returns
- T
The receiving object, cast to the requested interface if the proxy implements it and the interface was requested at proxy instantiation time; otherwise null.
Type Parameters
T
- A contract interface type.
Remarks
Typically a simple conditional cast would be sufficient to determine whether a proxy implements a given interface. However when AcceptProxyWithExtraInterfaces is true a proxy may be returned that implements extra interfaces. In such cases, this method can be used to determine whether the proxy was intentionally created to implement the interface or not, allowing feature testing to still happen since conditional casting might lead to false positives.
WithJsonRpcSettings<T>(IAsyncEnumerable<T>, JsonRpcEnumerableSettings?)
Decorates an IAsyncEnumerable<T> with settings that customize how StreamJsonRpc will send its items to the remote party.
public static IAsyncEnumerable<T> WithJsonRpcSettings<T>(this IAsyncEnumerable<T> enumerable, JsonRpcEnumerableSettings? settings)
Parameters
enumerable
IAsyncEnumerable<T>The enumerable to be decorated.
settings
JsonRpcEnumerableSettingsThe settings to associate with this enumerable.
Returns
- IAsyncEnumerable<T>
The decorated enumerable instance.
Type Parameters
T
The type of element enumerated by the sequence.
WithPrefetchAsync<T>(IAsyncEnumerable<T>, int, CancellationToken)
Preloads an IAsyncEnumerable<T> with a cache of pre-enumerated items for inclusion in the initial transmission of the enumerable over an RPC channel.
public static ValueTask<IAsyncEnumerable<T>> WithPrefetchAsync<T>(this IAsyncEnumerable<T> enumerable, int count, CancellationToken cancellationToken = default)
Parameters
enumerable
IAsyncEnumerable<T>The sequence to pre-fetch items from.
count
intThe number of items to pre-fetch. If this value is larger than the number of elements in the enumerable, all values will be pre-fetched.
cancellationToken
CancellationTokenA cancellation token.
Returns
- ValueTask<IAsyncEnumerable<T>>
A decorated IAsyncEnumerable<T> object that is specially prepared for processing by JSON-RPC with the preloaded values.
Type Parameters
T
The type of item in the collection.