Table of Contents

Class JsonExtensions

Namespace
ActivityPub.Types.Internal
Assembly
ActivityPub.Types.dll
internal static class JsonExtensions
Inheritance
JsonExtensions
Inherited Members

Methods

HasProperty(JsonElement, string)

Checks if the JsonElement contains a property with a specified name.

internal static bool HasProperty(this JsonElement element, string name)

Parameters

element JsonElement
name string

Returns

bool

ToNode(JsonElement, JsonNodeOptions?)

Converts a JsonElement to the appropriate JsonNode subtype.

internal static JsonNode? ToNode(this JsonElement element, JsonNodeOptions? options = null)

Parameters

element JsonElement

Element to convert

options JsonNodeOptions?

Optional options to pass to JsonNode

Returns

JsonNode

Node containing the same information

ToNodeOptions(JsonSerializerOptions)

Converts a JsonSerializerOptions into a JsonNodeOptions with the equivalent settings.

internal static JsonNodeOptions ToNodeOptions(this JsonSerializerOptions options)

Parameters

options JsonSerializerOptions

Returns

JsonNodeOptions

TryGetASType(JsonElement, out string?)

Attempts to read the provided JsonElement as an ActivityStreams object and return its type. Returns false if the element does not contain an object or the object does not contain a valid type.

internal static bool TryGetASType(this JsonElement element, out string? type)

Parameters

element JsonElement

object to read

type string

Set to the AS type on success, or null on failure

Returns

bool

Returns true on success, false on failure

TryGetString(JsonElement, out string?)

Attempts to read the element as a string. Returns true on success.

internal static bool TryGetString(this JsonElement element, out string? str)

Parameters

element JsonElement

Element to convert

str string

String that was read

Returns

bool

true if a string was read, false otherwise

TryGetString(Utf8JsonReader, out string?)

Attempts to read a string from the provided Utf8JsonReader. Returns false and null if the reader is not positioned at a string or reading fails. Does NOT advance the reader!

internal static bool TryGetString(this Utf8JsonReader reader, out string? type)

Parameters

reader Utf8JsonReader

Reader, not copied because we don't move it

type string

String that was read

Returns

bool

Returns true if a string was read, false otherwise.