Class JsonRpcRequest
- Namespace
- StreamJsonRpc.Protocol
- Assembly
- StreamJsonRpc.dll
Describes a method to be invoked on the server.
[DataContract]
[GenerateShape]
[MessagePackConverter(typeof(NerdbankMessagePackFormatter.JsonRpcRequestConverter))]
public class JsonRpcRequest : JsonRpcMessage, IJsonRpcMessageWithId
- Inheritance
-
JsonRpcRequest
- Implements
- Derived
- Inherited Members
Properties
ArgumentCount
Gets the number of arguments supplied in the request.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public virtual int ArgumentCount { get; }
Property Value
ArgumentListDeclaredTypes
Gets or sets a list of Type objects that describe how each element in ArgumentsList is expected by the server to be typed. If specified, this must have exactly the same length as ArgumentsList and contain no null elements.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public IReadOnlyList<Type>? ArgumentListDeclaredTypes { get; set; }
Property Value
Remarks
This property is not serialized into the JSON-RPC message. On the client-side of an RPC call it comes from the typed arguments supplied to the InvokeWithCancellationAsync<TResult>(string, IReadOnlyList<object?>?, IReadOnlyList<Type>?, CancellationToken) method. On the server-side of the RPC call it comes from the types of each parameter on the invoked RPC method. This list is used for purposes of aiding the IJsonRpcMessageFormatter in serialization.
ArgumentNames
Gets the sequence of argument names, if applicable.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public virtual IEnumerable<string>? ArgumentNames { get; }
Property Value
Arguments
Gets or sets the arguments to use when invoking the specified Method. Either an array of arguments or an object whose properties are used in a named arguments object.
[DataMember(Name = "params", Order = 3, IsRequired = false, EmitDefaultValue = false)]
[JsonPropertyName("params")]
[JsonPropertyOrder(3)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[PropertyShape(Name = "params", Order = 3)]
public object? Arguments { get; set; }
Property Value
- object
An array of arguments OR map of named arguments. Preferably either an instance of IReadOnlyDictionary<TKey, TValue> where the key is a string representing the name of the parameter and the value is the argument, or an array of object. If neither of these, ArgumentCount and TryGetArgumentByNameOrIndex(string?, int, Type?, out object?) should be overridden.
ArgumentsArray
Gets or sets an array of arguments, if applicable.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
[Obsolete("Use ArgumentsList instead.")]
public object?[]? ArgumentsArray { get; set; }
Property Value
- object[]
ArgumentsList
Gets or sets a read only list of arguments, if applicable.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public IReadOnlyList<object?>? ArgumentsList { get; set; }
Property Value
DebuggerDisplay
Gets the string to display in the debugger for this instance.
protected string DebuggerDisplay { get; }
Property Value
Id
Gets or sets an identifier established by the client if a response to the request is expected.
[Obsolete("Use RequestId instead.")]
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public object? Id { get; set; }
Property Value
IsNotification
Gets a value indicating whether this is a notification, and no response is expected.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public bool IsNotification { get; }
Property Value
IsResponseExpected
Gets a value indicating whether a response to this request is expected.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public bool IsResponseExpected { get; }
Property Value
Method
Gets or sets the name of the method to be invoked.
[DataMember(Name = "method", Order = 2, IsRequired = true)]
[JsonPropertyName("method")]
[JsonPropertyOrder(2)]
[JsonRequired]
[PropertyShape(Name = "method", Order = 2)]
public string? Method { get; set; }
Property Value
NamedArgumentDeclaredTypes
Gets or sets a dictionary of Type objects indexed by the property name that describe how each element in NamedArguments is expected by the server to be typed. If specified, this must have exactly the same size as NamedArguments and contain no null values.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public IReadOnlyDictionary<string, Type>? NamedArgumentDeclaredTypes { get; set; }
Property Value
Remarks
This property is not serialized into the JSON-RPC message. On the client-side of an RPC call it comes from the declared property types in the parameter object. On the server-side of the RPC call it comes from the types of each parameter on the invoked RPC method. This list is used for purposes of aiding the IJsonRpcMessageFormatter in serialization.
NamedArguments
Gets or sets the dictionary of named arguments, if applicable.
[IgnoreDataMember]
[JsonIgnore]
[PropertyShape(Ignore = true)]
public IReadOnlyDictionary<string, object?>? NamedArguments { get; set; }
Property Value
RequestId
Gets or sets an identifier established by the client if a response to the request is expected.
[DataMember(Name = "id", Order = 1, IsRequired = false, EmitDefaultValue = false)]
[JsonPropertyName("id")]
[JsonPropertyOrder(1)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[PropertyShape(Name = "id", Order = 1)]
public RequestId RequestId { get; set; }
Property Value
TraceParent
Gets or sets the data for the W3C Trace Context traceparent
value.
[DataMember(Name = "traceparent", EmitDefaultValue = false)]
[JsonPropertyName("traceparent")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[PropertyShape(Name = "traceparent")]
public string? TraceParent { get; set; }
Property Value
TraceState
Gets or sets the data for the W3C Trace Context tracestate
value.
[DataMember(Name = "tracestate", EmitDefaultValue = false)]
[JsonPropertyName("tracestate")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[PropertyShape(Name = "tracestate")]
public string? TraceState { get; set; }
Property Value
Methods
ToString()
public override string ToString()
Returns
TryGetArgumentByNameOrIndex(string?, int, Type?, out object?)
Retrieves an argument for the RPC request.
public virtual bool TryGetArgumentByNameOrIndex(string? name, int position, Type? typeHint, out object? value)
Parameters
name
stringThe name of the parameter that requires an argument. May be null if the caller knows they want a positional argument.
position
intThe index of the parameter that requires an argument. May be -1 for an argument with no position.
typeHint
TypeThe type of the parameter that requires an argument. May be null if the type need not be coerced.
value
objectReceives the value of the argument, if it exists. It MAY be returned even if it does not conform to
typeHint
.
Returns
- bool
true if an argument is available for a parameter with the given name or position; false otherwise.
Remarks
A derived-type may override this method in order to consider the typeHint
and deserialize the required argument on-demand such that it can satisfy the type requirement.
Exceptions
- RpcArgumentDeserializationException
Thrown if the argument exists, but cannot be deserialized.
TryGetTypedArguments(ReadOnlySpan<ParameterInfo>, Span<object?>)
Gets the arguments to supply to the method invocation, coerced to types that will satisfy the given list of parameters.
public virtual JsonRpcRequest.ArgumentMatchResult TryGetTypedArguments(ReadOnlySpan<ParameterInfo> parameters, Span<object?> typedArguments)
Parameters
parameters
ReadOnlySpan<ParameterInfo>The list of parameters that the arguments must satisfy.
typedArguments
Span<object>An array to initialize with arguments that can satisfy CLR type requirements for each of the
parameters
. The length of this span must equal the length ofparameters
.
Returns
- JsonRpcRequest.ArgumentMatchResult
true if all the arguments can conform to the types of the
parameters
andtypedArguments
is initialized; false otherwise.
Exceptions
- RpcArgumentDeserializationException
Thrown if the argument exists, but cannot be deserialized.