private JsonRpcRequest ReadRequest()

in src/StreamJsonRpc/JsonMessageFormatter.cs [734:789]


        private JsonRpcRequest ReadRequest(JToken json)
        {
            Requires.NotNull(json, nameof(json));

            RequestId id = json["id"]?.ToObject<RequestId>(DefaultSerializer) ?? default;

            // We leave arguments as JTokens at this point, so that we can try deserializing them
            // to more precise .NET types as required by the method we're invoking.
            JToken? args = json["params"];
            object? arguments =
                args is JObject argsObject ? PartiallyParseNamedArguments(argsObject) :
                args is JArray argsArray ? (object)PartiallyParsePositionalArguments(argsArray) :
                null;

            // If method is $/progress, get the progress instance from the dictionary and call Report
            string? method = json.Value<string>("method");

            if (this.formatterProgressTracker is not null && string.Equals(method, MessageFormatterProgressTracker.ProgressRequestSpecialMethod, StringComparison.Ordinal))
            {
                try
                {
                    JToken? progressId =
                        args is JObject ? args["token"] :
                        args is JArray ? args[0] :
                        null;

                    JToken? value =
                        args is JObject ? args["value"] :
                        args is JArray ? args[1] :
                        null;

                    MessageFormatterProgressTracker.ProgressParamInformation? progressInfo = null;
                    if (progressId is object && this.formatterProgressTracker.TryGetProgressObject(progressId.Value<long>(), out progressInfo))
                    {
                        object? typedValue = value?.ToObject(progressInfo.ValueType, this.JsonSerializer);
                        progressInfo.InvokeReport(typedValue);
                    }
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    this.rpc?.TraceSource.TraceData(TraceEventType.Error, (int)JsonRpc.TraceEvents.ProgressNotificationError, e);
                }
            }

            return new JsonRpcRequest(this)
            {
                RequestId = id,
                Method = json.Value<string>("method"),
                Arguments = arguments,
                TraceParent = json.Value<string>("traceparent"),
                TraceState = json.Value<string>("tracestate"),
                TopLevelPropertyBag = new TopLevelPropertyBag(this.JsonSerializer, (JObject)json),
            };
        }