From 1d7429943180aa1bc85edc7b9d2660278ab6cdae Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sun, 8 Dec 2024 20:30:40 -0500 Subject: [PATCH 1/2] [dotnet] Refactor away private constructor from `Response` --- dotnet/src/webdriver/Response.cs | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/dotnet/src/webdriver/Response.cs b/dotnet/src/webdriver/Response.cs index 0af9b181779b3..3e7b7b5947a29 100644 --- a/dotnet/src/webdriver/Response.cs +++ b/dotnet/src/webdriver/Response.cs @@ -56,19 +56,29 @@ public Response(SessionId sessionId) } } - private Response(Dictionary rawResponse) + /// + /// Returns a new from a JSON-encoded string. + /// + /// The JSON string to deserialize into a . + /// A object described by the JSON string. + public static Response FromJson(string responseJson) { + Dictionary rawResponse = JsonSerializer.Deserialize>(responseJson, s_jsonSerializerOptions) + ?? throw new WebDriverException("JSON success response returned \"null\" value"); + + var @this = new Response(); + if (rawResponse.ContainsKey("sessionId")) { if (rawResponse["sessionId"] != null) { - this.SessionId = rawResponse["sessionId"].ToString(); + @this.SessionId = rawResponse["sessionId"].ToString(); } } if (rawResponse.TryGetValue("value", out object value)) { - this.Value = value; + @this.Value = value; } // If the returned object does *not* have a "value" property @@ -76,37 +86,39 @@ private Response(Dictionary rawResponse) // TODO: Remove this if statement altogether; there should // never be a spec-compliant response that does not contain a // value property. - if (!rawResponse.ContainsKey("value") && this.Value == null) + if (!rawResponse.ContainsKey("value") && @this.Value == null) { // Special-case for the new session command, where the "capabilities" // property of the response is the actual value we're interested in. if (rawResponse.ContainsKey("capabilities")) { - this.Value = rawResponse["capabilities"]; + @this.Value = rawResponse["capabilities"]; } else { - this.Value = rawResponse; + @this.Value = rawResponse; } } - if (this.Value is Dictionary valueDictionary) + if (@this.Value is Dictionary valueDictionary) { // Special case code for the new session command. If the response contains // sessionId and capabilities properties, fix up the session ID and value members. if (valueDictionary.ContainsKey("sessionId")) { - this.SessionId = valueDictionary["sessionId"].ToString(); + @this.SessionId = valueDictionary["sessionId"].ToString(); if (valueDictionary.TryGetValue("capabilities", out object capabilities)) { - this.Value = capabilities; + @this.Value = capabilities; } else { - this.Value = valueDictionary["value"]; + @this.Value = valueDictionary["value"]; } } } + + return @this; } /// @@ -124,18 +136,6 @@ private Response(Dictionary rawResponse) /// public WebDriverResult Status { get; set; } - /// - /// Returns a new from a JSON-encoded string. - /// - /// The JSON string to deserialize into a . - /// A object described by the JSON string. - public static Response FromJson(string value) - { - Dictionary deserializedResponse = JsonSerializer.Deserialize>(value, s_jsonSerializerOptions) - ?? throw new WebDriverException("JSON success response returned \"null\" value"); - - return new Response(deserializedResponse); - } /// /// Returns a new from a JSON-encoded string. From 7ce68091a5a5d05753839090842891cd12bad5e1 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 11 Dec 2024 13:03:36 -0500 Subject: [PATCH 2/2] Rename `Response` local and parameter --- dotnet/src/webdriver/Response.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/dotnet/src/webdriver/Response.cs b/dotnet/src/webdriver/Response.cs index 3e7b7b5947a29..abe4bb2a9fcdd 100644 --- a/dotnet/src/webdriver/Response.cs +++ b/dotnet/src/webdriver/Response.cs @@ -59,26 +59,26 @@ public Response(SessionId sessionId) /// /// Returns a new from a JSON-encoded string. /// - /// The JSON string to deserialize into a . + /// The JSON string to deserialize into a . /// A object described by the JSON string. - public static Response FromJson(string responseJson) + public static Response FromJson(string value) { - Dictionary rawResponse = JsonSerializer.Deserialize>(responseJson, s_jsonSerializerOptions) + Dictionary rawResponse = JsonSerializer.Deserialize>(value, s_jsonSerializerOptions) ?? throw new WebDriverException("JSON success response returned \"null\" value"); - var @this = new Response(); + var response = new Response(); if (rawResponse.ContainsKey("sessionId")) { if (rawResponse["sessionId"] != null) { - @this.SessionId = rawResponse["sessionId"].ToString(); + response.SessionId = rawResponse["sessionId"].ToString(); } } - if (rawResponse.TryGetValue("value", out object value)) + if (rawResponse.TryGetValue("value", out object valueObj)) { - @this.Value = value; + response.Value = valueObj; } // If the returned object does *not* have a "value" property @@ -86,39 +86,39 @@ public static Response FromJson(string responseJson) // TODO: Remove this if statement altogether; there should // never be a spec-compliant response that does not contain a // value property. - if (!rawResponse.ContainsKey("value") && @this.Value == null) + if (!rawResponse.ContainsKey("value") && response.Value == null) { // Special-case for the new session command, where the "capabilities" // property of the response is the actual value we're interested in. if (rawResponse.ContainsKey("capabilities")) { - @this.Value = rawResponse["capabilities"]; + response.Value = rawResponse["capabilities"]; } else { - @this.Value = rawResponse; + response.Value = rawResponse; } } - if (@this.Value is Dictionary valueDictionary) + if (response.Value is Dictionary valueDictionary) { // Special case code for the new session command. If the response contains // sessionId and capabilities properties, fix up the session ID and value members. if (valueDictionary.ContainsKey("sessionId")) { - @this.SessionId = valueDictionary["sessionId"].ToString(); + response.SessionId = valueDictionary["sessionId"].ToString(); if (valueDictionary.TryGetValue("capabilities", out object capabilities)) { - @this.Value = capabilities; + response.Value = capabilities; } else { - @this.Value = valueDictionary["value"]; + response.Value = valueDictionary["value"]; } } } - return @this; + return response; } ///