Skip to main content
Version: Preview (0.3.0-preview.205)

Struct AnyEntityId

Namespace: AdCodicem.ValueObjects.Identifiers
Assembly: AdCodicem.ValueObjects.Identifiers.dll

An identifier of any registered type, resolved from its prefix.

[JsonConverter(typeof(AnyEntityIdJsonConverter))]
[TypeConverter(typeof(AnyEntityIdTypeConverter))]
public readonly struct AnyEntityId : IEquatable<AnyEntityId>, ISpanParsable<AnyEntityId>, IParsable<AnyEntityId>, ISpanFormattable, IFormattable

Implements​

IEquatable<AnyEntityId>, ISpanParsable<AnyEntityId>, IParsable<AnyEntityId>, ISpanFormattable, IFormattable

Inherited Members​

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

Remarks​

This serves the places where the type is not known until the text arrives: a webhook body naming the resource it concerns, a deep link, an audit trail recording heterogeneous references. Resolution costs a bounded number of dictionary lookups and no reflection.

It deliberately implements neither nor , and that is what makes it non-persistable by construction rather than by convention: the Entity Framework Core integration keys off those interfaces, so this type is invisible to it and no one can map a polymorphic column by accident. It is a transport and resolution type, nothing more.

Properties​

IsDefault​

Gets a value indicating whether this instance is the uninitialized default.

public bool IsDefault { get; }

Property Value​

bool

Prefix​

Gets the prefix the identifier carries, without its trailing separator.

public string Prefix { get; }

Property Value​

string

Value​

Gets the canonical text of the identifier.

public string Value { get; }

Property Value​

string

Remarks​

The identifier's own Value, which a formatting hook declared on the identifier type never changes.

ValueObjectType​

Gets the identifier type this text belongs to, or null for the default instance.

public Type? ValueObjectType { get; }

Property Value​

Type?

Methods​

Equals(AnyEntityId)​

Indicates whether the current object is equal to another object of the same type.

public bool Equals(AnyEntityId other)

Parameters​

other AnyEntityId

An object to compare with this object.

Returns​

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)​

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters​

obj object?

The object to compare with the current instance.

Returns​

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()​

Returns the hash code for this instance.

public override int GetHashCode()

Returns​

int

A 32-bit signed integer that is the hash code for this instance.

Is<TId>()​

Determines whether this identifier belongs to a given type.

public bool Is<TId>() where TId : struct, IEntityId<TId>

Returns​

bool

true when the prefix resolved to TId.

Type Parameters​

TId

Identifier type to test against.

Parse(ReadOnlySpan<char>, IFormatProvider?)​

Parses text carrying any registered prefix.

public static AnyEntityId Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)

Parameters​

s ReadOnlySpan<char>

Text to parse.

provider IFormatProvider?

Unused; identifiers are culture-independent.

Returns​

AnyEntityId

The resolved identifier.

Exceptions​

ValueObjectException

The text is not a valid identifier of any registered type.

Parse(string, IFormatProvider?)​

Parses text carrying any registered prefix.

public static AnyEntityId Parse(string s, IFormatProvider? provider = null)

Parameters​

s string

Text to parse.

provider IFormatProvider?

Unused; identifiers are culture-independent.

Returns​

AnyEntityId

The resolved identifier.

Exceptions​

ValueObjectException

The text is not a valid identifier of any registered type.

ToString()​

Returns the fully qualified type name of this instance.

public override string ToString()

Returns​

string

The fully qualified type name.

ToString(string?, IFormatProvider?)​

Formats the value of the current instance using the specified format.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters​

format string?

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the implementation.

formatProvider IFormatProvider?

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns​

string

The value of the current instance in the specified format.

ToValueObject()​

Builds the concrete identifier, boxed.

public object? ToValueObject()

Returns​

object?

The boxed identifier, or null for the default instance.

Remarks​

For callers that only hold a — a dispatcher looking up a handler, for instance. Prefer wherever the type is known.

TryConvertTo<TId>(out TId)​

Converts to a concrete identifier type.

public bool TryConvertTo<TId>(out TId result) where TId : struct, IEntityId<TId>

Parameters​

result TId

The typed identifier, or default when this is not one.

Returns​

bool

true when the conversion succeeded.

Type Parameters​

TId

Identifier type to convert to.

Remarks​

The type test comes first, so converting to the wrong type costs a reference comparison rather than a parse that was always going to fail.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)​

Tries to format the value of the current instance into the provided span of characters.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)

Parameters​

destination Span<char>

The span in which to write this instance's value formatted as a span of characters.

charsWritten int

When this method returns, contains the number of characters that were written in destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.

provider IFormatProvider?

An optional object that supplies culture-specific formatting information for destination.

Returns​

bool

true if the formatting was successful; otherwise, false.

TryParse(ReadOnlySpan<char>, IFormatProvider?, out AnyEntityId)​

Parses text carrying any registered prefix, without throwing.

public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out AnyEntityId result)

Parameters​

s ReadOnlySpan<char>

Text to parse.

provider IFormatProvider?

Unused; identifiers are culture-independent.

result AnyEntityId

The resolved identifier, or default when the text is rejected.

Returns​

bool

true when the text was accepted.

TryParse(ReadOnlySpan<char>, IFormatProvider?, out AnyEntityId, out ValidationResult)​

Parses text carrying any registered prefix, reporting why it was rejected.

public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out AnyEntityId result, out ValidationResult validation)

Parameters​

s ReadOnlySpan<char>

Text to parse.

provider IFormatProvider?

Unused; identifiers are culture-independent.

result AnyEntityId

The resolved identifier, or default when the text is rejected.

validation ValidationResult

The outcome, distinguishing a prefix no type claims from a prefix that resolves but whose body is corrupt — a caller that cannot tell the two apart cannot write a useful error message.

Returns​

bool

true when the text was accepted.

TryParse(string?, IFormatProvider?, out AnyEntityId)​

Tries to parse a string into a value.

public static bool TryParse(string? s, IFormatProvider? provider, out AnyEntityId result)

Parameters​

s string?

The string to parse.

provider IFormatProvider?

An object that provides culture-specific formatting information about s.

result AnyEntityId

When this method returns, contains the result of successfully parsing s or an undefined value on failure.

Returns​

bool

true if s was successfully parsed; otherwise, false.

Operators​

operator ==(AnyEntityId, AnyEntityId)​

Determines whether two identifiers are equal.

public static bool operator ==(AnyEntityId left, AnyEntityId right)

Parameters​

left AnyEntityId

Left operand.

right AnyEntityId

Right operand.

Returns​

bool

true when both are equal.

operator !=(AnyEntityId, AnyEntityId)​

Determines whether two identifiers differ.

public static bool operator !=(AnyEntityId left, AnyEntityId right)

Parameters​

left AnyEntityId

Left operand.

right AnyEntityId

Right operand.

Returns​

bool

true when they differ.