Table of Contents

Class RangeAttribute

Namespace
Trellis
Assembly
Trellis.Core.dll

Specifies the minimum and maximum allowed values for numeric value objects (RequiredInt<TSelf>, RequiredDecimal<TSelf>, RequiredLong<TSelf>).

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

Examples

[Range(1, 999)]
public partial class Quantity : RequiredInt<Quantity> { }

[Range(0.01, 99.99)]
public partial class UnitPrice : RequiredDecimal<UnitPrice> { }

[Range(0L, 5_000_000_000L)]
public partial class LargeId : RequiredLong<LargeId> { }

Remarks

The source generator reads the constructor arguments at compile time and emits range validation in the generated TryCreate method. This attribute does not rely on runtime reflection.

Note: This is Trellis.RangeAttribute, not System.ComponentModel.DataAnnotations.RangeAttribute. If your project imports System.ComponentModel.DataAnnotations, use the fully qualified name [Trellis.Range(min, max)] to avoid ambiguity.

Constructors

RangeAttribute(double, double)

Specifies a double range. Use for RequiredDecimal<TSelf> with fractional bounds. C# does not allow decimal in attribute constructors, so double is used.

public RangeAttribute(double minimum, double maximum)

Parameters

minimum double
maximum double

RangeAttribute(int, int)

Specifies an int range. Use for RequiredInt<TSelf> and RequiredDecimal<TSelf> (whole numbers).

public RangeAttribute(int minimum, int maximum)

Parameters

minimum int
maximum int

RangeAttribute(long, long)

Specifies a long range. Use for RequiredLong<TSelf>.

public RangeAttribute(long minimum, long maximum)

Parameters

minimum long
maximum long

Properties

Code

Gets or sets an application-defined reason code that replaces the framework default on every failure this attribute produces.

public string? Code { get; set; }

Property Value

string

A non-empty code, or null to keep the framework default. Setting it to an empty or whitespace string is a generator error (TRLS060).

Remarks

The framework vocabulary is frozen so that one client catalog entry works across every Trellis service. An application that owns both ends of its own contract — it wrote the declaration and it writes the catalog key — may name the failure in its own terms instead, and nothing it does here can invalidate another party's catalog. An override carries no warning and no penalty.

See Also