Class RpcTargetMetadata
- Namespace
- StreamJsonRpc
- Assembly
- StreamJsonRpc.dll
Describes an RPC target type, which can be an interface or a class.
public class RpcTargetMetadata
- Inheritance
-
RpcTargetMetadata
- Inherited Members
Properties
AliasedMethods
Gets method aliases that can be invoked on this RPC target.
public required IReadOnlyDictionary<string, IReadOnlyList<RpcTargetMetadata.TargetMethodMetadata>> AliasedMethods { get; init; }
Property Value
Events
Gets the list of events that can be raised by this RPC target.
public required IReadOnlyList<RpcTargetMetadata.EventMetadata> Events { get; init; }
Property Value
Methods
Gets the (unaliased) methods that can be invoked on this RPC target.
public required IReadOnlyDictionary<string, IReadOnlyList<RpcTargetMetadata.TargetMethodMetadata>> Methods { get; init; }
Property Value
TargetType
Gets the type of the RPC target, which can be an interface or a class.
public required Type TargetType { get; init; }
Property Value
Methods
EnableDynamicEventHandlerCreation()
Enables dynamic generation of event handlers for EventHandler<TEventArgs> delegates
where TEventArgs
is a value type.
public static void EnableDynamicEventHandlerCreation()
Remarks
This method is not safe to use in NativeAOT applications. Such applications should either call RegisterEventArgs<TEventArgs>() directly for each value-type type argument, or rely on source generation to do so.
FromClass(Type)
Creates a new instance of RpcTargetMetadata for the specified class type, including all of its RPC target members.
public static RpcTargetMetadata FromClass(Type classType)
Parameters
classType
TypeThe type representing the class for which to generate metadata. Must not be null and should be a concrete class type.
Returns
- RpcTargetMetadata
An RpcTargetMetadata instance containing metadata for the specified class and its interfaces.
Remarks
While convenient, this method produces the least trimmable code. For a smaller trimmed application, use FromClass(Type, ClassAndInterfaces) instead.
FromClass(Type, ClassAndInterfaces)
Creates an instance of RpcTargetMetadata for the specified class type using the provided metadata. All public methods and events will be exposed to RPC clients, unless JsonRpcIgnoreAttribute is applied to them.
public static RpcTargetMetadata FromClass(Type classType, RpcTargetMetadata.ClassAndInterfaces metadata)
Parameters
classType
TypeThe class Type for which to generate metadata. Must be a non-null class type.
metadata
RpcTargetMetadata.ClassAndInterfacesThe metadata describing the class and its interfaces. Must not be null and must correspond to the specified class type.
Returns
- RpcTargetMetadata
An RpcTargetMetadata instance representing the public methods and events of the specified class.
Remarks
If metadata for the specified class type has already been created, the existing instance is returned. Otherwise, a new instance is generated. If all interfaces implemented by the class are present in the provided metadata, the resulting instance will be cached for later reuse.
Exceptions
- ArgumentException
Thrown if the
classType
does not match the StreamJsonRpc.RpcTargetMetadata.ClassAndInterfaces.ClassType in the provided metadata.
FromClassNonPublic(Type)
Creates an instance of RpcTargetMetadata for the specified class type, including non-public members that are not attributed with JsonRpcIgnoreAttribute.
public static RpcTargetMetadata FromClassNonPublic(Type classType)
Parameters
classType
TypeThe type of the class for which to generate metadata. Must not be null.
Returns
- RpcTargetMetadata
A RpcTargetMetadata instance containing metadata for the specified class type, including its non-public members.
Remarks
While convenient, this method produces the least trimmable code. For a smaller trimmed application, use FromClassNonPublic(Type, ClassAndInterfaces) instead.
FromClassNonPublic(Type, ClassAndInterfaces)
Creates an instance of RpcTargetMetadata for the specified class type using the provided metadata. All methods and events will be exposed to RPC clients, including non-public members, unless JsonRpcIgnoreAttribute is applied to them.
public static RpcTargetMetadata FromClassNonPublic(Type classType, RpcTargetMetadata.ClassAndInterfaces metadata)
Parameters
classType
TypeThe class Type for which to generate metadata. Must be a non-null class type.
metadata
RpcTargetMetadata.ClassAndInterfacesThe metadata describing the class and its interfaces. Must not be null and must correspond to the specified class type.
Returns
- RpcTargetMetadata
An RpcTargetMetadata instance representing the public methods and events of the specified class.
Remarks
If metadata for the specified class type has already been created, the existing instance is returned. Otherwise, a new instance is generated. If all interfaces implemented by the class are present in the provided metadata, the resulting instance will be cached for later reuse.
Exceptions
- ArgumentException
Thrown if the
classType
does not match the StreamJsonRpc.RpcTargetMetadata.ClassAndInterfaces.ClassType in the provided metadata.
FromInterface(InterfaceCollection)
Creates metadata describing the RPC target for the specified set of interfaces.
public static RpcTargetMetadata FromInterface(RpcTargetMetadata.InterfaceCollection interfaces)
Parameters
interfaces
RpcTargetMetadata.InterfaceCollectionA collection of interfaces, including the primary interface and any interfaces it derives from, to generate metadata for.
Returns
- RpcTargetMetadata
An instance of RpcTargetMetadata representing the RPC target metadata for the provided interfaces.
Remarks
If metadata for the specified interface has already been created, the existing instance is returned. Otherwise, a new metadata instance is generated. This method is typically used to obtain metadata required for dispatching or proxying RPC calls based on an interface definition.
Exceptions
- ArgumentException
Thrown if
interfaces
does not represent all the interfaces that the target interface derives from.
FromInterface(Type)
Creates an instance of RpcTargetMetadata that describes the specified RPC contract interface.
public static RpcTargetMetadata FromInterface(Type rpcContract)
Parameters
rpcContract
TypeThe interface type that defines the RPC contract. Must not be null and must represent an interface type.
Returns
- RpcTargetMetadata
An RpcTargetMetadata instance that provides metadata for the specified RPC contract interface.
Remarks
If metadata for the specified interface has already been created, the existing instance is returned. Otherwise, a new metadata instance is generated. This method is typically used to obtain metadata required for dispatching or proxying RPC calls based on an interface definition.
While convenient, this method produces the least trimmable code. For a smaller trimmed application, use FromInterface(InterfaceCollection) instead.
FromShape(ITypeShape)
Creates an RpcTargetMetadata instance from the specified shape.
public static RpcTargetMetadata FromShape(ITypeShape shape)
Parameters
shape
ITypeShapeThe shape to create the metadata from.
Returns
- RpcTargetMetadata
An RpcTargetMetadata instance initialized from the
shape
.
FromShape<T>(ITypeShapeProvider)
Creates an RpcTargetMetadata instance from the specified shape.
public static RpcTargetMetadata FromShape<T>(ITypeShapeProvider provider)
Parameters
provider
ITypeShapeProviderThe provider of type shapes from which to obtain the shape.
Returns
- RpcTargetMetadata
An RpcTargetMetadata instance initialized from the shape of the
T
.
Type Parameters
T
The type for which a shape should be obtained and RpcTargetMetadata generated for.
RegisterEventArgs<TEventArgs>()
Creates an event handler factory that supports EventHandler<TEventArgs> for a given TEventArgs
.
public static void RegisterEventArgs<TEventArgs>() where TEventArgs : struct
Type Parameters
TEventArgs
The type argument used in EventHandler<TEventArgs>. Only structs are supported because only value types need registration. Reference types work without registration.