Table of Contents

Class JsonRpcProxy

Namespace
Nerdbank.JsonRpc
Assembly
Nerdbank.JsonRpc.dll

Provides lifecycle and capability behavior shared by generated RPC and direct proxies.

public abstract class JsonRpcProxy : IClientProxy, IDisposable, IAsyncDisposable
Inheritance
JsonRpcProxy
Implements
Inherited Members
Extension Methods

Constructors

JsonRpcProxy(ServiceProxyContext, Type, IReadOnlyList<Type>)

Initializes a new instance of the JsonRpcProxy class for direct calls.

protected JsonRpcProxy(ServiceProxyContext context, Type primaryInterface, IReadOnlyList<Type> enabledInterfaces)

Parameters

context ServiceProxyContext

The target and policy context.

primaryInterface Type

The always-enabled primary contract.

enabledInterfaces IReadOnlyList<Type>

The additional enabled contracts.

JsonRpcProxy(IJsonRpcClient, JsonRpcProxyOptions, Type)

Initializes a new instance of the JsonRpcProxy class for RPC calls.

protected JsonRpcProxy(IJsonRpcClient client, JsonRpcProxyOptions options, Type primaryInterface)

Parameters

client IJsonRpcClient

The RPC invocation client.

options JsonRpcProxyOptions

The proxy options.

primaryInterface Type

The always-enabled primary contract.

Properties

Client

Gets the RPC invocation client when this proxy uses RPC.

protected IJsonRpcClient Client { get; }

Property Value

IJsonRpcClient

Context

Gets the target context used by generated forwarding methods.

protected ServiceProxyContext Context { get; }

Property Value

ServiceProxyContext

LocalContext

Gets the direct-call context, or null when this proxy uses RPC.

protected ServiceProxyContext? LocalContext { get; }

Property Value

ServiceProxyContext

MethodNameTransform

Gets the transform used to compute RPC method names.

protected Func<string, string> MethodNameTransform { get; }

Property Value

Func<string, string>

UseNamedArguments

Gets a value indicating whether RPC arguments are named.

protected bool UseNamedArguments { get; }

Property Value

bool

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DisposeUnowned()

Invokes the contract's remote disposal operation when no local resource is owned.

protected virtual void DisposeUnowned()

Is(Type)

Gets a value indicating whether a contract interface is enabled on this proxy.

public bool Is(Type type)

Parameters

type Type

The contract interface type to query.

Returns

bool

true if the proxy implements the interface and it is enabled; otherwise false.

Remarks

The primary contract and its inherited interfaces are always enabled on generated proxies. Enabling an additional interface also enables its inherited interfaces. Non-interface types return false.

Exceptions

ArgumentNullException

Thrown when type is null.

IsInterfaceEnabled(Type, ServiceProxyLease)

Tests invocation capabilities against the retained target rather than the context's current generation.

protected bool IsInterfaceEnabled(Type type, ServiceProxyLease lease)

Parameters

type Type

The invoked contract.

lease ServiceProxyLease

The lease retaining the invocation target.

Returns

bool

Whether both this proxy and the retained target enable the contract.

TryDispose()

Disposes the owned resource or direct-call context, if present.

protected bool TryDispose()

Returns

bool

Whether disposal was handled without a remote call.