Class OptionJsonExtensions
Extension methods for using System.Text.Json types with Option<T>.
Inherited Members
Namespace: RustyOptions
Assembly: RustyOptions.dll
Syntax
public static class OptionJsonExtensions
Methods
| Edit this page View SourceGetOption<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> |
|
Type Parameters
| Name | Description |
|---|---|
| T |
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> |
|
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> |
|
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> |
|
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> |
|
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> |
|
Type Parameters
| Name | Description |
|---|---|
| T | The value type to convert to. |