Skip to main content

Class UnderlyingValue

Namespace: AdCodicem.ValueObjects
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Thin generic bridges to the underlying type's own parsing and formatting, used by generated code.

public static class UnderlyingValue

Inheritance

objectUnderlyingValue

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks

Going through a constrained generic call rather than naming Guid.TryParse, Decimal.TryParse and the rest one by one keeps the generator honest: any type reachable here is guaranteed by the compiler to expose the API, and the JIT devirtualizes the call for the concrete type argument, so nothing is paid at run time for the indirection.

Methods

Abs<TValue>(TValue)

Returns the absolute value of a numeric underlying value.

public static TValue Abs<TValue>(TValue value) where TValue : INumberBase<TValue>

Parameters

value TValue

Value to take the absolute value of.

Returns

TValue

The absolute value.

Type Parameters

TValue

Underlying value type.

Remarks

The numeric constants of the BCL primitives are static abstract members of INumberBase, reachable only through a type parameter. These bridges are how generated code names them.

IsZero<TValue>(TValue)

Determines whether a numeric underlying value is zero.

public static bool IsZero<TValue>(TValue value) where TValue : INumberBase<TValue>

Parameters

value TValue

Value to test.

Returns

bool

true when the value is zero.

Type Parameters

TValue

Underlying value type.

Remarks

The numeric constants of the BCL primitives are static abstract members of INumberBase, reachable only through a type parameter. These bridges are how generated code names them.

One<TValue>()

Gets the multiplicative identity of a numeric underlying type.

public static TValue One<TValue>() where TValue : INumberBase<TValue>

Returns

TValue

One.

Type Parameters

TValue

Underlying value type.

Remarks

The numeric constants of the BCL primitives are static abstract members of INumberBase, reachable only through a type parameter. These bridges are how generated code names them.

TryFormat<TValue>(in TValue, Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Formats a value into a destination span using the underlying type's own formatter.

public static bool TryFormat<TValue>(in TValue value, Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) where TValue : ISpanFormattable

Parameters

value TValue

Value to format.

destination Span<char>

Destination buffer.

charsWritten int

Number of characters written.

format ReadOnlySpan<char>

Format specifier.

provider IFormatProvider?

Format provider.

Returns

bool

true when the value fitted in destination.

Type Parameters

TValue

Underlying value type.

Remarks

Several BCL types, among them, implement the four-argument explicitly and only expose a shorter public overload. Routing through a constrained type parameter reaches the interface method uniformly, and the call is devirtualized for the concrete type argument.

TryParse<TValue>(ReadOnlySpan<char>, IFormatProvider?, out TValue)

Parses a span using the underlying type's own parser.

public static bool TryParse<TValue>(ReadOnlySpan<char> text, IFormatProvider? provider, out TValue value) where TValue : ISpanParsable<TValue>

Parameters

text ReadOnlySpan<char>

Text to parse.

provider IFormatProvider?

Format provider.

value TValue

The parsed value.

Returns

bool

true when the text was parsed.

Type Parameters

TValue

Underlying value type.

TryParse<TValue>(string?, IFormatProvider?, out TValue)

Parses a string using the underlying type's own parser.

public static bool TryParse<TValue>(string? text, IFormatProvider? provider, out TValue value) where TValue : IParsable<TValue>

Parameters

text string?

Text to parse.

provider IFormatProvider?

Format provider.

value TValue

The parsed value.

Returns

bool

true when the text was parsed.

Type Parameters

TValue

Underlying value type.

Zero<TValue>()

Gets the additive identity of a numeric underlying type.

public static TValue Zero<TValue>() where TValue : INumberBase<TValue>

Returns

TValue

Zero.

Type Parameters

TValue

Underlying value type.

Remarks

The numeric constants of the BCL primitives are static abstract members of INumberBase, reachable only through a type parameter. These bridges are how generated code names them.