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
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
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.
TryConvertToInteger<TNumber, TValue>(TNumber, out TValue)
Converts a number to an integer type with a checked conversion that never truncates.
public static bool TryConvertToInteger<TNumber, TValue>(TNumber number, out TValue value) where TNumber : INumberBase<TNumber> where TValue : IBinaryInteger<TValue>
Parameters
number TNumber
Number to convert.
value TValue
The same number, as a TValue.
Returns
true when TValue holds the number whole; false when the
number is out of its range, has a fraction, or is not a number at all.
Type Parameters
TNumber
Type of the number to convert.
TValue
Integer type to convert it to.
Remarks
The type converter of a numeric value object goes through it for a number of another numeric type than its own,
such as the 7.5
becoming 7, and that is refused too.
TryConvertToReal<TNumber, TValue>(TNumber, out TValue)
Converts a number to a real type with a checked conversion.
public static bool TryConvertToReal<TNumber, TValue>(TNumber number, out TValue value) where TNumber : INumberBase<TNumber> where TValue : IFloatingPoint<TValue>
Parameters
number TNumber
Number to convert.
value TValue
The nearest TValue to the number.
Returns
true when the number is within the range of TValue;
false when it is beyond it, or is NaN or an infinity, which a
Type Parameters
TNumber
Type of the number to convert.
TValue
Real type to convert it to:
Remarks
The type converter of a numeric value object goes through it as it goes through
0.1 converted to a 16777216f would become 16777220. It is read from its shortest round-trip text instead,
which keeps every digit it holds, as the Newtonsoft.Json converter reads a JSON number Newtonsoft.Json turned into
a NaN and an
infinity carry over to a
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 buffer.
charsWritten int
Number of characters written.
format ReadOnlySpan<char>
Format specifier.
provider IFormatProvider?
Format provider.
Returns
true when the value fitted in destination.
Type Parameters
TValue
Underlying value type.
Remarks
Several BCL types,
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
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
true when the text was parsed.
Type Parameters
TValue
Underlying value type.
TryParse<TValue>(ReadOnlySpan<char>, NumberStyles, IFormatProvider?, out TValue)
Parses a span using the underlying number type's own parser, with the given styles in the invariant culture.
public static bool TryParse<TValue>(ReadOnlySpan<char> text, NumberStyles invariantStyle, IFormatProvider? provider, out TValue value) where TValue : INumberBase<TValue>
Parameters
text ReadOnlySpan<char>
Text to parse.
invariantStyle NumberStyles
The styles the text is read with when provider is null or the invariant
culture.
provider IFormatProvider?
Format provider. null stands for
value TValue
The parsed value.
Returns
true when the text was parsed.
Type Parameters
TValue
Underlying value type.
Remarks
The own styles of 12,5, would read as 125. Generated
code hands those styles over without fr-FR reads 12,5 as 12.5.
The invariant culture is recognized by equality, so a decimal.Parse pass as often.
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.