Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Add not-null Response.Value helper #15243

Merged
merged 9 commits into from
Feb 6, 2025
16 changes: 16 additions & 0 deletions dotnet/src/webdriver/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using OpenQA.Selenium.Internal;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -215,6 +216,21 @@ public string ToJson()
return JsonSerializer.Serialize(this);
}

/// <summary>
/// Throws if <see cref="Value"/> is <see langword="null"/>.
/// </summary>
/// <exception cref="WebDriverException">If <see cref="Value"/> is <see langword="null"/>.</exception>
[MemberNotNull(nameof(Value))]
internal Response EnsureValueIsNotNull()
{
if (Value is null)
{
throw new WebDriverException("Response from remote end doesn't have $.Value property");
}

return this;
}

/// <summary>
/// Returns the object as a string.
/// </summary>
Expand Down
Loading