Skip to content

Commit 95258d6

Browse files
RenderMichaelsandeepsuryaprasad
authored andcommitted
[dotnet] Add not-null Response.Value helper (SeleniumHQ#15243)
* [dotnet] Add not-null `Response.Value` helper * Use other style * update method name * add custom error message * EnsureValueIsNotNull can return itself * Improve message * Improve message
1 parent cf64163 commit 95258d6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

dotnet/src/webdriver/Response.cs

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using OpenQA.Selenium.Internal;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Globalization;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -215,6 +216,21 @@ public string ToJson()
215216
return JsonSerializer.Serialize(this);
216217
}
217218

219+
/// <summary>
220+
/// Throws if <see cref="Value"/> is <see langword="null"/>.
221+
/// </summary>
222+
/// <exception cref="WebDriverException">If <see cref="Value"/> is <see langword="null"/>.</exception>
223+
[MemberNotNull(nameof(Value))]
224+
internal Response EnsureValueIsNotNull()
225+
{
226+
if (Value is null)
227+
{
228+
throw new WebDriverException("Response from remote end doesn't have $.Value property");
229+
}
230+
231+
return this;
232+
}
233+
218234
/// <summary>
219235
/// Returns the object as a string.
220236
/// </summary>

0 commit comments

Comments
 (0)