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
TypestringThe 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.IdstringOptional 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
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
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
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
idobjectOptional resource identifier.
Returns
- ResourceRef
A resource reference.
Type Parameters
TResourceThe resource type.