Class Age
- Namespace
- Trellis.Primitives
- Assembly
- Trellis.Primitives.dll
Age value object with validation for ages 0-150.
[JsonConverter(typeof(ParsableJsonConverter<Age>))]
public class Age : ScalarValueObject<Age, int>, IComparable<ValueObject>, IComparable, IEquatable<ValueObject>, IConvertible, IFormattable, IFormattableScalarValue<Age, int>, IScalarValue<Age, int>, IParsable<Age>
- Inheritance
-
Age
- Implements
- Inherited Members
- Extension Methods
Remarks
Validation Rules (Opinionated):
- Must be non-negative (>= 0)
- Must be realistic (<= 150)
If these rules don't fit your domain, create your own Age value object using the ScalarValueObject<TSelf, T> base class from the DomainDrivenDesign package.
Methods
Parse(string?, IFormatProvider?)
Parses an age.
public static Age Parse(string? s, IFormatProvider? provider)
Parameters
sstringproviderIFormatProvider
Returns
TryCreate(int, string?)
Attempts to create an age.
public static Result<Age> TryCreate(int value, string? fieldName = null)
Parameters
Returns
TryCreate(string?, IFormatProvider?, string?)
Attempts to create an Age from a string using the specified format provider.
public static Result<Age> TryCreate(string? value, IFormatProvider? provider, string? fieldName = null)
Parameters
valuestringThe string value to parse.
providerIFormatProviderThe format provider for culture-sensitive parsing. Defaults to InvariantCulture when null.
fieldNamestringOptional field name for validation error messages.
Returns
TryCreate(string?, string?)
Attempts to create an Age from a string representation.
public static Result<Age> TryCreate(string? value, string? fieldName = null)
Parameters
Returns
TryParse(string?, IFormatProvider?, out Age)
Tries to parse an age.
public static bool TryParse(string? s, IFormatProvider? provider, out Age result)
Parameters
sstringproviderIFormatProviderresultAge