Skip to content

Commit 3358983

Browse files
[dotnet] Obsolete setters and constructors on Response that are not conducive to immutability (#15107)
* [dotnet] Obsoletes setters on `Response` type * [dotnet] Obsolete constructors on `Response` that are not conducive to immutability * Avoid obsolete `Response` constructor
1 parent 48ba3a1 commit 3358983

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

dotnet/src/webdriver/Remote/HttpCommandExecutor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ private Response CreateResponse(HttpResponseInfo responseInfo)
325325

326326
if (response.Value is string valueString)
327327
{
328-
response.Value = valueString.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
328+
valueString = valueString.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
329+
response = new Response(response.SessionId, valueString, response.Status);
329330
}
330331

331332
return response;

dotnet/src/webdriver/Response.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class Response
4242
/// <summary>
4343
/// Initializes a new instance of the <see cref="Response"/> class
4444
/// </summary>
45+
[Obsolete("Set all values using the Response(string, object, WebDriverResult) constructor instead. This constructor will be removed in Selenium 4.30")]
4546
public Response()
4647
{
4748
}
@@ -50,6 +51,7 @@ public Response()
5051
/// Initializes a new instance of the <see cref="Response"/> class
5152
/// </summary>
5253
/// <param name="sessionId">Session ID in use</param>
54+
[Obsolete("Set all values using the Response(string, object, WebDriverResult) constructor instead. This constructor will be removed in Selenium 4.30")]
5355
public Response(SessionId? sessionId)
5456
{
5557
this.SessionId = sessionId?.ToString();
@@ -136,18 +138,35 @@ public static Response FromJson(string value)
136138
/// <summary>
137139
/// Gets or sets the value from JSON.
138140
/// </summary>
139-
public object? Value { get; set; }
141+
public object? Value
142+
{
143+
get;
144+
145+
[Obsolete("The Response type will be immutable and this setter will be removed in Selenium 4.30")]
146+
set;
147+
}
140148

141149
/// <summary>
142150
/// Gets or sets the session ID.
143151
/// </summary>
144-
public string? SessionId { get; set; }
152+
public string? SessionId
153+
{
154+
get;
155+
156+
[Obsolete("The Response type will be immutable and this setter will be removed in Selenium 4.30")]
157+
set;
158+
}
145159

146160
/// <summary>
147161
/// Gets or sets the status value of the response.
148162
/// </summary>
149-
public WebDriverResult Status { get; set; }
163+
public WebDriverResult Status
164+
{
165+
get;
150166

167+
[Obsolete("The Response type will be immutable and this setter will be removed in Selenium 4.30")]
168+
set;
169+
}
151170

152171
/// <summary>
153172
/// Returns a new <see cref="Response"/> from a JSON-encoded string.

0 commit comments

Comments
 (0)