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

Class EntityIdAttribute

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

Marks a readonly partial struct as a public entity identifier and drives code generation for it.

[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
public sealed class EntityIdAttribute : Attribute

Inheritance​

object ← Attribute ← EntityIdAttribute

Inherited Members​

Attribute.Equals(object?), Attribute.GetCustomAttribute(Assembly, Type), Attribute.GetCustomAttribute(Assembly, Type, bool), Attribute.GetCustomAttribute(MemberInfo, Type), Attribute.GetCustomAttribute(MemberInfo, Type, bool), Attribute.GetCustomAttribute(Module, Type), Attribute.GetCustomAttribute(Module, Type, bool), Attribute.GetCustomAttribute(ParameterInfo, Type), Attribute.GetCustomAttribute(ParameterInfo, Type, bool), Attribute.GetCustomAttributes(Assembly), Attribute.GetCustomAttributes(Assembly, bool), Attribute.GetCustomAttributes(Assembly, Type), Attribute.GetCustomAttributes(Assembly, Type, bool), Attribute.GetCustomAttributes(MemberInfo), Attribute.GetCustomAttributes(MemberInfo, bool), Attribute.GetCustomAttributes(MemberInfo, Type), Attribute.GetCustomAttributes(MemberInfo, Type, bool), Attribute.GetCustomAttributes(Module), Attribute.GetCustomAttributes(Module, bool), Attribute.GetCustomAttributes(Module, Type), Attribute.GetCustomAttributes(Module, Type, bool), Attribute.GetCustomAttributes(ParameterInfo), Attribute.GetCustomAttributes(ParameterInfo, bool), Attribute.GetCustomAttributes(ParameterInfo, Type), Attribute.GetCustomAttributes(ParameterInfo, Type, bool), Attribute.GetHashCode(), Attribute.IsDefaultAttribute(), Attribute.IsDefined(Assembly, Type), Attribute.IsDefined(Assembly, Type, bool), Attribute.IsDefined(MemberInfo, Type), Attribute.IsDefined(MemberInfo, Type, bool), Attribute.IsDefined(Module, Type), Attribute.IsDefined(Module, Type, bool), Attribute.IsDefined(ParameterInfo, Type), Attribute.IsDefined(ParameterInfo, Type, bool), Attribute.Match(object?), Attribute.TypeId, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Examples​

[EntityId("acc")]
public readonly partial struct AccountId;

Remarks​

Everything [ValueObject<string>] generates is generated here too — construction, parsing, formatting, equality, ordering, the JSON converter, the TypeConverter and the registry entry — plus New(), Prefix and Granularity. The length constraints and the OpenAPI pattern are derived from the profile and flow into the database column and the schema exactly as a hand-declared rule would: the rule is still stated once.

This attribute lives in the package that carries its runtime rather than in the contracts package. Were it shipped with the core package alone, a consumer could annotate a type and receive a compile error inside generated code they cannot edit; here, without the package the attribute simply does not exist.

Constructors​

EntityIdAttribute(string)​

Initializes the annotation with the prefix identifiers of this type carry.

public EntityIdAttribute(string prefix)

Parameters​

prefix string

One or more lowercase segments separated by _, each opening on a letter — acc, cus, sk_live. Reported by VO0015 when malformed and by VO0016 when another type in the compilation already claims it.

Properties​

AllowDefault​

Gets or sets a value indicating whether the analyzer tolerates default and parameterless construction.

public bool AllowDefault { get; set; }

Property Value​

bool

Remarks​

Those expressions produce an identifier that never went through validation: its Value is empty and its IsDefault is true. They are reported as errors by the analyzers shipped with AdCodicem.ValueObjects unless this is set, exactly as for . An identifier that may be missing is a nullable one, so this is for the rare type whose default state is meaningful to the code holding it.

Description​

Gets or sets the description surfaced in the OpenAPI schema.

public string? Description { get; set; }

Property Value​

string?

Remarks​

Defaults to the XML documentation summary of the declaring type when it has one.

Example​

Gets or sets an example value surfaced in the OpenAPI schema.

public string? Example { get; set; }

Property Value​

string?

Remarks​

Defaults to an identifier of the right shape, built at compile time from the profile.

Granularity​

Gets or sets the width of the time bucket heading the body. Defaults to .

public IdGranularity Granularity { get; set; }

Property Value​

IdGranularity

Remarks​

Pick it from the insert rate of the table: a bucket holding roughly 10⁴–10⁵ rows keeps the hot part of the index cached. It leaks the creation time at this granularity and nothing finer, and never affects how guessable an identifier is — the random part keeps its 80 bits either way.

Prefix​

Gets the prefix identifiers of this type carry, without its trailing separator.

public string Prefix { get; }

Property Value​

string

Remarks​

The prefix is what makes a mixed-up identifier fail at the boundary rather than in a repository: cus_… cannot be parsed as an AccountId. It is stored in the database for the same reason, so that even a query the application never sees cannot join two tables on each other's keys.