Skip to content

Commit 5a17dea

Browse files
sanych-sunBorisDog
andauthored
CSHARP-5786: Add Decimal128 ctor overload for byte/short, for compatibility with net10 (#1819) (#1820)
(cherry picked from commit 1ef7fcc) Co-authored-by: BorisDog <[email protected]>
1 parent 0153b18 commit 5a17dea

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/MongoDB.Bson/ObjectModel/Decimal128.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,25 @@ public Decimal128(Half value)
15231523
}
15241524
#endif
15251525

1526+
/// <summary>
1527+
/// Initializes a new instance of the <see cref="Decimal128"/> struct.
1528+
/// </summary>
1529+
/// <param name="value">The value.</param>
1530+
[CLSCompliant(false)]
1531+
public Decimal128(sbyte value)
1532+
{
1533+
if (value >= 0)
1534+
{
1535+
_highBits = 0;
1536+
_lowBits = (ulong)value;
1537+
}
1538+
else
1539+
{
1540+
_highBits = Flags.SignBit;
1541+
_lowBits = value == sbyte.MinValue ? (ulong)sbyte.MaxValue + 1 : (ulong)-value;
1542+
}
1543+
}
1544+
15261545
/// <summary>
15271546
/// Initializes a new instance of the <see cref="Decimal128"/> struct.
15281547
/// </summary>
@@ -1559,6 +1578,16 @@ public Decimal128(long value)
15591578
}
15601579
}
15611580

1581+
/// <summary>
1582+
/// Initializes a new instance of the <see cref="Decimal128"/> struct.
1583+
/// </summary>
1584+
/// <param name="value">The value.</param>
1585+
public Decimal128(byte value)
1586+
{
1587+
_highBits = 0;
1588+
_lowBits = value;
1589+
}
1590+
15621591
/// <summary>
15631592
/// Initializes a new instance of the <see cref="Decimal128"/> struct.
15641593
/// </summary>

0 commit comments

Comments
 (0)