-
Couldn't load subscription status.
- Fork 114
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
The .NET decimal type doesn't expose a proper API for extracting raw values without allocating an int[] unless you target .NET.
But .NET Standard targets can do this too by leveraging the field layout of the struct being intentionally the same between the two.
namespace Windows.Win32.Foundation
{
/// <content>
/// Adds implicit conversion from decimal to DECIMAL.
/// </content>
internal partial struct DECIMAL
{
public static unsafe implicit operator DECIMAL(decimal value)
{
// DECIMAL is layout-compatible with decimal.
return *(DECIMAL*)&value;
}
}
}Also, the converter that is emitted is buggy:
public static implicit operator decimal(DECIMAL value)
{
return new decimal(
(int)value.Anonymous2.Anonymous.Lo32, (int)value.Anonymous2.Anonymous.Mid32, (int)value.Hi32, value.Anonymous1.Anonymous.sign == 0x80, value.Anonymous1.Anonymous.scale);
}This throws OverflowException as it casts uint fields to int values without unchecked.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request