Table of Contents

Struct ResourceRef

Namespace
Trellis
Assembly
Trellis.Core.dll

Identifies a resource by its type and optional identifier. Used as the typed payload for resource-oriented errors such as Error.NotFound, Error.Conflict, Error.Gone, and Error.PreconditionFailed.

public readonly record struct ResourceRef : IEquatable<ResourceRef>
Implements
Inherited Members
Extension Methods

Constructors

ResourceRef(string, string?)

Identifies a resource by its type and optional identifier. Used as the typed payload for resource-oriented errors such as Error.NotFound, Error.Conflict, Error.Gone, and Error.PreconditionFailed.

public ResourceRef(string Type, string? Id = null)

Parameters

Type string

The resource type name (e.g. "User", "Order"). Use For<TResource>(object?) when the CLR type name is the desired resource name, or For(string, object?) when a custom domain name is needed. Required.

Id string

Optional identifier of the specific resource instance. May be null when the error applies to the resource collection rather than a specific instance.

Properties

Id

Optional identifier of the specific resource instance. May be null when the error applies to the resource collection rather than a specific instance.

public string? Id { get; init; }

Property Value

string

Type

The resource type name (e.g. "User", "Order"). Use For<TResource>(object?) when the CLR type name is the desired resource name, or For(string, object?) when a custom domain name is needed. Required.

public string Type { get; init; }

Property Value

string

Methods

For(string, object?)

Creates a resource reference from an explicit resource type name and optional identifier.

public static ResourceRef For(string type, object? id = null)

Parameters

type string

The resource type name.

id object

Optional resource identifier.

Returns

ResourceRef

A resource reference.

For<TResource>(object?)

Creates a resource reference whose resource type is typeof(TResource).Name.

public static ResourceRef For<TResource>(object? id = null)

Parameters

id object

Optional resource identifier.

Returns

ResourceRef

A resource reference.

Type Parameters

TResource

The resource type.