Skip to content

Struct AssetRef

Namespace: Apogee.Core.Assets
Assembly: Apogee.Core.dll

A reference to an asset by its path and its . The path is what people read and is tried first; when the file is no longer there, the UID finds it where it was moved. Either part may be missing. The path is kept exactly as given: this type does not normalise it (the asset database does).

The text form is res://models/car.glb|uid://4k2m9x7q1w3ze; a path alone and a UID alone (uid://4k2m9x7q1w3ze) are also valid, and the empty text is the empty reference. | cannot be part of a path.

public readonly record struct AssetRef : IEquatable<AssetRef>

Implements

IEquatable<AssetRef>

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

AssetRef(string, AssetUid)

A reference to an asset by its path and its . The path is what people read and is tried first; when the file is no longer there, the UID finds it where it was moved. Either part may be missing. The path is kept exactly as given: this type does not normalise it (the asset database does).

The text form is res://models/car.glb|uid://4k2m9x7q1w3ze; a path alone and a UID alone (uid://4k2m9x7q1w3ze) are also valid, and the empty text is the empty reference. | cannot be part of a path.

public AssetRef(string Path, AssetUid Uid)

Parameters

Path string

The path, such as res://models/car.glb or mod://id/a.png; empty (or null in default) when there is none.

Uid AssetUid

The UID, or .

Fields

Separator

The character between the path and the UID in the text form.

public const char Separator = '|'

Field Value

char

Properties

HasPath

Whether there is a path.

public bool HasPath { get; }

Property Value

bool

IsEmpty

Whether there is neither a path nor a UID.

public bool IsEmpty { get; }

Property Value

bool

Path

The path, such as res://models/car.glb or mod://id/a.png; empty (or null in default) when there is none.

public string Path { get; init; }

Property Value

string

Uid

The UID, or .

public AssetUid Uid { get; init; }

Property Value

AssetUid

Methods

FromPath(string)

A reference by path alone.

public static AssetRef FromPath(string path)

Parameters

path string

Returns

AssetRef

Exceptions

ArgumentException

The path is empty, contains | or starts with uid:// (it would read back as a UID).

FromUid(AssetUid)

A reference by UID alone.

public static AssetRef FromUid(AssetUid uid)

Parameters

uid AssetUid

Returns

AssetRef

Parse(ReadOnlySpan<char>)

Reads the text form (see ).

public static AssetRef Parse(ReadOnlySpan<char> text)

Parameters

text ReadOnlySpan<char>

Returns

AssetRef

Exceptions

FormatException

The text is not a valid asset reference.

ToString()

The text form: the path, path|uid://…, uid://… alone, or an empty string for the empty reference.

public override string ToString()

Returns

string

TryParse(ReadOnlySpan<char>, out AssetRef)

Reads the text form. Fails on a | with an empty path or an empty or invalid UID after it, on a second |, and on text that starts with uid:// but is not a valid UID. The empty text is the empty reference.

public static bool TryParse(ReadOnlySpan<char> text, out AssetRef value)

Parameters

text ReadOnlySpan<char>

The text.

value AssetRef

The reference, or the empty reference on failure.

Returns

bool

Whether the text was valid.