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)
Initialises a new ResourceCollectionNameAttribute.
public ResourceCollectionNameAttribute(string name)
Parameters
namestringThe collection-name path segment.
Exceptions
- ArgumentNullException
Thrown when
nameisnull.- ArgumentException
Thrown when
nameis empty, whitespace, or contains any character outside the RFC 3986unreservedset (ASCII letters and digits plus-,.,_,~).
Properties
Name
The collection-name path segment to use in synthesised resource URIs.
public string Name { get; }
Property Value
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
namestringThe candidate path segment.
nullreturnsfalse.
Returns
- bool
truewhen the value is safe to use unencoded as a single path segment.