RunicTextReference class

Namespace Runic.Application.Views in Runic.Application.Views 0.23.0

public sealed class RunicTextReference : IEquatable<RunicTextReference>

Inherits or implements IEquatable.

A text reference of Runic Translations, held as its wire JSON: a catalog, a message key, typed arguments and an optional fallback text. The page shows it in the window's language with the Translations ESM runtime, so text that a ViewModel produces follows a language switch without a call per string (the text-reference wire type).

Remarks

A ViewModel member, DTO member or command result of type Runic.Translations.TranslationReference crosses the Bridge without this type; the generator recognizes it by name, so the Views packages do not depend on Runic Translations. Use RunicTextReference where Views code needs a reference, such as RunicValidationMessage.Text and RunicValidationResult.Text, or where the application only has the JSON:

var text = RunicTextReference.Create(reference, TranslationReferenceJsonContext.Default.TranslationReference);

Reading checks the shape of the reference, as the Translations readers do: an object with an integer version of at least 1, a catalog, a contractFingerprint, a nonempty key, an arguments object and, when present, a string fallbackText (or null in version 1), at most 256 KiB of UTF-8. A later version is accepted: the Translations runtime that shows the reference reports a version it does not read, and shows the fallback text, as it does for a reference that does not match its catalog.

Fields

MaximumUtf8Bytes

public const int MaximumUtf8Bytes = 262144

The largest reference in UTF-8 bytes, as the Translations transport allows.

Properties

Catalog

public string Catalog { get; }

The catalog id.

ContractFingerprint

public string ContractFingerprint { get; }

The writer's catalog contract fingerprint.

FallbackText

public string? FallbackText { get; }

The text to show when the page cannot translate the reference, if the writer stored one.

Key

public string Key { get; }

The message key, such as title_too_long.

Utf8Json

public ReadOnlyMemory<byte> Utf8Json { get; }

The reference's JSON, as UTF-8.

Version

public int Version { get; }

The transport version: 1, 2, or a later one that the page's Translations runtime may not read.

Methods

Create

public static RunicTextReference Create<T>(T reference, JsonTypeInfo<T> typeInfo)

Creates a reference from a value that its source-generated JSON metadata writes as a text reference, such as a Runic.Translations.TranslationReference with TranslationReferenceJsonContext.Default.TranslationReference.

Exceptions

ArgumentNullException

An argument is null.

JsonException

The value is not written as a text reference.

Equals

public bool Equals(RunicTextReference? other)

Whether both references have the same JSON.

Equals

public override bool Equals(object? obj)

Inherits documentation from Object.Equals.

GetHashCode

public override int GetHashCode()

Inherits documentation from Object.GetHashCode.

Parse

public static RunicTextReference Parse(string json)

Reads a reference from its JSON text.

Exceptions

ArgumentNullException

json is null.

JsonException

The text is not one JSON value of a text reference's shape.

Parse

public static RunicTextReference Parse(ReadOnlySpan<byte> utf8Json)

Reads a reference from its UTF-8 JSON.

Exceptions

JsonException

The text is not one JSON value of a text reference's shape.

Read

public static RunicTextReference Read(JsonElement value)

Reads a reference from a JSON value, such as a member of a message.

Exceptions

JsonException

The value does not have a text reference's shape.

ToJson

public string ToJson()

The reference's JSON text.

ToString

public override string ToString()

The fallback text, or the key when the reference has none.

WriteTo

public void WriteTo(Utf8JsonWriter writer)

Writes the reference as one JSON value.