From 63e9a4788526c39b5996d05166a275daefaa6cd4 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 17 Jan 2025 16:24:56 -0500 Subject: [PATCH 1/3] [dotnet] Obsoletes setters on `Response` type --- .../webdriver/Remote/HttpCommandExecutor.cs | 2 ++ dotnet/src/webdriver/Response.cs | 23 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs index 85921d73954be..bb8663ddd4e56 100644 --- a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs +++ b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs @@ -340,7 +340,9 @@ private Response CreateResponse(HttpResponseInfo responseInfo) if (response.Value is string valueString) { +#pragma warning disable CS0618 // Response.Value setter can be used internally response.Value = valueString.Replace("\r\n", "\n").Replace("\n", Environment.NewLine); +#pragma warning restore CS0618 } return response; diff --git a/dotnet/src/webdriver/Response.cs b/dotnet/src/webdriver/Response.cs index 9a0de908859a5..e0b6bbfad55b4 100644 --- a/dotnet/src/webdriver/Response.cs +++ b/dotnet/src/webdriver/Response.cs @@ -136,18 +136,35 @@ public static Response FromJson(string value) /// /// Gets or sets the value from JSON. /// - public object? Value { get; set; } + public object? Value + { + get; + + [Obsolete("The Response type will be immutable and this setter will be removed in Selenium 4.30")] + set; + } /// /// Gets or sets the session ID. /// - public string? SessionId { get; set; } + public string? SessionId + { + get; + + [Obsolete("The Response type will be immutable and this setter will be removed in Selenium 4.30")] + set; + } /// /// Gets or sets the status value of the response. /// - public WebDriverResult Status { get; set; } + public WebDriverResult Status + { + get; + [Obsolete("The Response type will be immutable and this setter will be removed in Selenium 4.30")] + set; + } /// /// Returns a new from a JSON-encoded string. From faa138db65738ebd6dc0a0fa0e649c41cbcd2102 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 17 Jan 2025 16:27:45 -0500 Subject: [PATCH 2/3] [dotnet] Obsolete constructors on `Response` that are not conducive to immutability --- dotnet/src/webdriver/Response.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dotnet/src/webdriver/Response.cs b/dotnet/src/webdriver/Response.cs index e0b6bbfad55b4..c6ac73328b1d7 100644 --- a/dotnet/src/webdriver/Response.cs +++ b/dotnet/src/webdriver/Response.cs @@ -42,6 +42,7 @@ public class Response /// /// Initializes a new instance of the class /// + [Obsolete("Set all values using the Response(string, object, WebDriverResult) constructor instead. This constructor will be removed in Selenium 4.30")] public Response() { } @@ -50,6 +51,7 @@ public Response() /// Initializes a new instance of the class /// /// Session ID in use + [Obsolete("Set all values using the Response(string, object, WebDriverResult) constructor instead. This constructor will be removed in Selenium 4.30")] public Response(SessionId? sessionId) { this.SessionId = sessionId?.ToString(); From 789eaa72d460f9eb2ef833a19bec2bc0589b27bd Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 17 Jan 2025 16:52:22 -0500 Subject: [PATCH 3/3] Avoid obsolete `Response` constructor --- dotnet/src/webdriver/Remote/HttpCommandExecutor.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs index bb8663ddd4e56..d8a44d46e2149 100644 --- a/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs +++ b/dotnet/src/webdriver/Remote/HttpCommandExecutor.cs @@ -340,9 +340,8 @@ private Response CreateResponse(HttpResponseInfo responseInfo) if (response.Value is string valueString) { -#pragma warning disable CS0618 // Response.Value setter can be used internally - response.Value = valueString.Replace("\r\n", "\n").Replace("\n", Environment.NewLine); -#pragma warning restore CS0618 + valueString = valueString.Replace("\r\n", "\n").Replace("\n", Environment.NewLine); + response = new Response(response.SessionId, valueString, response.Status); } return response;