Table of Contents

Interface IFormattableScalarValue<TSelf, TPrimitive>

Namespace
Trellis
Assembly
Trellis.Results.dll

Extended interface for scalar value objects that support culture-sensitive string parsing. Use for numeric and date types where IFormatProvider matters for parsing.

public interface IFormattableScalarValue<TSelf, TPrimitive> : IScalarValue<TSelf, TPrimitive> where TSelf : IFormattableScalarValue<TSelf, TPrimitive> where TPrimitive : IComparable

Type Parameters

TSelf

The value object type itself (CRTP pattern)

TPrimitive

The underlying primitive type (must be IComparable)

Inherited Members

Remarks

This interface extends IScalarValue<TSelf, TPrimitive> to add an overload of TryCreate that accepts an IFormatProvider for culture-sensitive parsing.

Implemented by types whose underlying primitive requires locale-aware parsing:

  • Integer types (e.g., Age) — thousand separators vary by culture
  • Decimal types (e.g., MonetaryAmount, Percentage) — decimal separators vary by culture
  • DateTime types — date formats vary by culture

NOT implemented by string-based types (EmailAddress, PhoneNumber, etc.) where IFormatProvider is irrelevant for parsing.

Methods

TryCreate(string?, IFormatProvider?, string?)

Attempts to create a validated scalar value from a string using the specified format provider. Use for culture-sensitive parsing of numeric and date values.

public static abstract Result<TSelf> TryCreate(string? value, IFormatProvider? provider, string? fieldName = null)

Parameters

value string

The raw string value to parse and validate.

provider IFormatProvider

The format provider for culture-sensitive parsing. When null, implementations should default to InvariantCulture.

fieldName string

Optional field name for validation error messages. If null, implementations should use a default field name based on the type name.

Returns

Result<TSelf>

Success with the scalar value, or Failure with validation errors.