Class ValueObjectAttribute<TValue>
Namespace: AdCodicem.ValueObjects.Annotations
Assembly: AdCodicem.ValueObjects.Abstractions.dll
Marks a readonly partial struct as a single-value value object and drives code generation for it.
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
public sealed class ValueObjectAttribute<TValue> : Attribute
Type Parameters
TValue
Underlying value type. Supported types are
Inheritance
object ← Attribute ← ValueObjectAttribute<TValue>
Inherited Members
Attribute.Equals(object?), Attribute.GetCustomAttribute(Assembly, Type), Attribute.GetCustomAttribute(Assembly, Type, bool), Attribute.GetCustomAttribute(MemberInfo, Type), Attribute.GetCustomAttribute(MemberInfo, Type, bool), Attribute.GetCustomAttribute(Module, Type), Attribute.GetCustomAttribute(Module, Type, bool), Attribute.GetCustomAttribute(ParameterInfo, Type), Attribute.GetCustomAttribute(ParameterInfo, Type, bool), Attribute.GetCustomAttributes(Assembly), Attribute.GetCustomAttributes(Assembly, bool), Attribute.GetCustomAttributes(Assembly, Type), Attribute.GetCustomAttributes(Assembly, Type, bool), Attribute.GetCustomAttributes(MemberInfo), Attribute.GetCustomAttributes(MemberInfo, bool), Attribute.GetCustomAttributes(MemberInfo, Type), Attribute.GetCustomAttributes(MemberInfo, Type, bool), Attribute.GetCustomAttributes(Module), Attribute.GetCustomAttributes(Module, bool), Attribute.GetCustomAttributes(Module, Type), Attribute.GetCustomAttributes(Module, Type, bool), Attribute.GetCustomAttributes(ParameterInfo), Attribute.GetCustomAttributes(ParameterInfo, bool), Attribute.GetCustomAttributes(ParameterInfo, Type), Attribute.GetCustomAttributes(ParameterInfo, Type, bool), Attribute.GetHashCode(), Attribute.IsDefaultAttribute(), Attribute.IsDefined(Assembly, Type), Attribute.IsDefined(Assembly, Type, bool), Attribute.IsDefined(MemberInfo, Type), Attribute.IsDefined(MemberInfo, Type, bool), Attribute.IsDefined(Module, Type), Attribute.IsDefined(Module, Type, bool), Attribute.IsDefined(ParameterInfo, Type), Attribute.IsDefined(ParameterInfo, Type, bool), Attribute.Match(object?), Attribute.TypeId, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
The declaring type opts into a rule by implementing the interface that declares it, so the compiler checks
its signature: VO0011 rather than silently ignored.
Declarative constraints set on this attribute (
Properties
AllowDefault
Gets or sets a value indicating whether the analyzer tolerates default and parameterless construction.
public bool AllowDefault { get; set; }
Property Value
Remarks
Those expressions produce an instance that never went through validation. They are reported as errors by
the analyzers shipped with AdCodicem.ValueObjects unless this is set, which is occasionally needed
for a value object whose default state is meaningful, such as a sequence number starting at zero.
AllowEmpty
Gets or sets a value indicating whether an empty string is accepted.
public bool AllowEmpty { get; set; }
Property Value
Remarks
Only meaningful for null.
Arithmetic
Gets or sets a value indicating whether arithmetic operators and
public bool Arithmetic { get; set; }
Property Value
Remarks
Requires a numeric underlying type. Every result is re-validated.
Comparison
Gets or sets how two values are compared for equality, ordering and hashing.
public StringComparison Comparison { get; set; }
Property Value
Remarks
Only meaningful when the underlying type is
Description
Gets or sets the description surfaced in the OpenAPI schema.
public string? Description { get; set; }
Property Value
Remarks
Defaults to the XML documentation summary of the declaring type when it is available.
Example
Gets or sets an example value surfaced in the OpenAPI schema.
public string? Example { get; set; }
Property Value
ExplicitConversionFromValue
Gets or sets a value indicating whether an explicit conversion from the underlying value is generated.
public bool ExplicitConversionFromValue { get; set; }
Property Value
Remarks
The conversion validates, and throws
ImplicitConversionToValue
Gets or sets a value indicating whether an implicit conversion to the underlying value is generated.
public bool ImplicitConversionToValue { get; set; }
Property Value
Remarks
Reading stays terse (string s = iban;) while construction remains explicit and validated.
MaxLength
Gets or sets the maximum accepted length. A negative value means unconstrained.
public int MaxLength { get; set; }
Property Value
Remarks
Only meaningful for maxLength OpenAPI keyword and used by the
EF Core integration to size the column, so the value object maps to a bounded column rather than an
unbounded one.
Maximum
Gets or sets the inclusive upper bound, written in invariant culture.
public string? Maximum { get; set; }
Property Value
Remarks
Expressed as text so that minimum OpenAPI keyword.
MinLength
Gets or sets the minimum accepted length. A negative value means unconstrained.
public int MinLength { get; set; }
Property Value
Remarks
Only meaningful for minLength OpenAPI keyword.
Minimum
Gets or sets the inclusive lower bound, written in invariant culture.
public string? Minimum { get; set; }
Property Value
Remarks
Expressed as text so that minimum OpenAPI keyword.
Pattern
Gets or sets a regular expression the normalized value must match.
[StringSyntax("Regex")]
public string? Pattern { get; set; }
Property Value
Remarks
Compiled once into a static Regex with RegexOptions.Compiled: one source generator cannot
see another's output, so [GeneratedRegex] is not reachable from emitted code. Also emitted as the
pattern keyword of the OpenAPI schema.
SchemaFormat
Gets or sets the value of the OpenAPI format keyword for the generated schema.
public string? SchemaFormat { get; set; }
Property Value
Remarks
Defaults to the natural format of the underlying type, such as uuid, date or int64.
ValueSet
Gets or sets whether the type accepts any valid value or only the declared
public ValueSetKind ValueSet { get; set; }