Table of Contents

Class ResourceCollectionNameAttribute

Namespace
Trellis
Assembly
Trellis.Core.dll

Overrides the naive plural form used when the framework synthesises a canonical resource URI for ProblemDetails.Instance from a ResourceRef. The default form is ResourceRef.Type.ToLowerInvariant() + "s"; this attribute lets the consumer supply an irregular plural (Person → people) or a domain-specific collection segment (UserAccount → accounts).

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class ResourceCollectionNameAttribute : Attribute
Inheritance
ResourceCollectionNameAttribute
Inherited Members
Extension Methods

Examples

[ResourceCollectionName("people")]
public sealed class Person { /* ... */ }

Remarks

The attribute is read by Trellis.Asp.AddResourceCollectionNames(Assembly) at startup and cached for the lifetime of the host. Apply it to the aggregate or resource type whose CLR name is reported by For<TResource>(object?).

Name must be a single URL-safe path segment composed of RFC 3986 unreserved characters only: ASCII letters and digits plus -, ., _, and ~. Reserved characters (/, ?, #), percent-encoded triplets (%2F), +, and whitespace are rejected because the value is emitted unencoded into the synthesised Instance URI and would otherwise change the URI's shape or meaning. Validation happens in the attribute constructor so a misconfigured override is surfaced at type-load (not at the first failing request).

Constructors

ResourceCollectionNameAttribute(string)

public ResourceCollectionNameAttribute(string name)

Parameters

name string

The collection-name path segment.

Exceptions

ArgumentNullException

Thrown when name is null.

ArgumentException

Thrown when name is empty, whitespace, or contains any character outside the RFC 3986 unreserved set (ASCII letters and digits plus -, ., _, ~).

Properties

Name

The collection-name path segment to use in synthesised resource URIs.

public string Name { get; }

Property Value

string

Methods

IsSafePathSegment(string?)

Returns true when name is a non-empty, non-whitespace string composed entirely of RFC 3986 unreserved characters (ASCII letters and digits plus -, ., _, ~). Reserved characters (/, ?, #), percent (%), +, and any whitespace return false. Exposed so that other framework components consuming a ResourceCollectionNameAttribute-equivalent override can apply the same validation rule.

public static bool IsSafePathSegment(string? name)

Parameters

name string

The candidate path segment. null returns false.

Returns

bool

true when the value is safe to use unencoded as a single path segment.