Open
Description
This idea addresses scenarios #82 and #83.
This new operator would take the form: CVal(
<Expression>,
<Type>)
Where <Expression> can be of the following types:
- Object type:
Object
- Signed integers:
SByte, Int16, Int32, Int64
- Unsigned integers:
Byte, UInt16, UInt32, UInt64
- Floating-Point:
Single, Double, Decimal
- Character type:
Char
- Any enumeration type
Note: This excludes type parameter types.
And <Type> can be any of the above types excluding Object
.
Note: This excludes type parameter types.
The behavior is as follows:
- From Object to any valid target type, a native CLR unbox conversion shall be used.
- Between signed and unsigned integers, the bits of the integer shall be re-interpreted with the new type.
- If the destination type has more bits than the source type the result shall be sign-extended.
- If the destination type has fewer bits than the source type, the result shall truncate the excess bits.
- From any floating-point type to a signed integer type, the fractional portion of the floating-point value shall be truncated.
- For negative values this truncates "up" to zero.
- From the character type to any signed or unsigned integer type, the result shall be the Unicode 16 value of the character.
- From any signed or unsigned integer type to the character type, the result shall be the character indicated by that Unicode 16 value.
- For values larger than 16-bits, excess bits shall be truncated.
- Conversions to or from enumeration types shall behave as if those conversions were being performed to or from the underlying integer type of the enumeration.
- Conversion overflow/underflow checking is governed by the checked/unchecked settings of the project.
Open questions:
- Nullable/lifted conversions
- Conversions between Boolean and integer types
- Reconcile behavior being orthogonal to overflow/underflow settings with above behavior that truncates excess bits.