Show / Hide Table of Contents

Class OptionJsonExtensions

Extension methods for using System.Text.Json types with Option<T>.

Inheritance
object
OptionJsonExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: RustyOptions
Assembly: RustyOptions.dll
Syntax
public static class OptionJsonExtensions

Methods

| Edit this page View Source

GetOption<T>(JsonValue)

Attempts to get the underlying JSON value as the specified type.

Declaration
public static Option<T> GetOption<T>(this JsonValue self) where T : notnull
Parameters
Type Name Description
JsonValue self
Returns
Type Description
Option<T>

Some(value) if the underlying value could be successfully converted, otherwise None.

Type Parameters
Name Description
T
| Edit this page View Source

GetPropOption(JsonElement, ReadOnlySpan<byte>)

Gets the indicated property element as an Option<T>

Declaration
public static Option<JsonElement> GetPropOption(this JsonElement self, ReadOnlySpan<byte> propertyName)
Parameters
Type Name Description
JsonElement self

The json element to read from.

ReadOnlySpan<byte> propertyName

The name of the property to retrieve.

Returns
Type Description
Option<JsonElement>

Some(JsonElement) if the property was found, otherwise None.

| Edit this page View Source

GetPropOption(JsonElement, ReadOnlySpan<char>)

Gets the indicated property element as an Option<T>

Declaration
public static Option<JsonElement> GetPropOption(this JsonElement self, ReadOnlySpan<char> propertyName)
Parameters
Type Name Description
JsonElement self

The json element to read from.

ReadOnlySpan<char> propertyName

The name of the property to retrieve.

Returns
Type Description
Option<JsonElement>

Some(JsonElement) if the property was found, otherwise None.

| Edit this page View Source

GetPropOption(JsonElement, string)

Gets the indicated property element as an Option<T>

Declaration
public static Option<JsonElement> GetPropOption(this JsonElement self, string propertyName)
Parameters
Type Name Description
JsonElement self

The json element to read from.

string propertyName

The name of the property to retrieve.

Returns
Type Description
Option<JsonElement>

Some(JsonElement) if the property was found, otherwise None.

| Edit this page View Source

GetPropOption(JsonObject, string)

Gets the indicated propery node as an Option<T>.

Declaration
public static Option<JsonNode> GetPropOption(this JsonObject self, string propertyName)
Parameters
Type Name Description
JsonObject self

The JSON node to read from.

string propertyName

The name of the property to retrieve.

Returns
Type Description
Option<JsonNode>

None if the property was not present, otherwise Some(node)

| Edit this page View Source

GetPropValue<T>(JsonObject, string)

Attempts to get a property with the given name as the given data type. Does not support array properties - use GetPropOption for arrays.

Declaration
public static Option<T> GetPropValue<T>(this JsonObject self, string propertyName) where T : notnull
Parameters
Type Name Description
JsonObject self

The JsonObject to get the property from.

string propertyName

The name of the property to retrieve.

Returns
Type Description
Option<T>

None if the property was not present or could not be parsed into the indicated type. Otherwise, Some(value).

Type Parameters
Name Description
T

The value type to convert to.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX