From f819b470d64d937e10078222caacb90245f1b57b Mon Sep 17 00:00:00 2001 From: BorisDog Date: Wed, 19 Nov 2025 11:02:04 -0800 Subject: [PATCH] CSHARP-5786: Add Decimal128 ctor overload for byte/short, for compatibility with net10 --- src/MongoDB.Bson/ObjectModel/Decimal128.cs | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/MongoDB.Bson/ObjectModel/Decimal128.cs b/src/MongoDB.Bson/ObjectModel/Decimal128.cs index 3320e7dc37b..0853fdf99e1 100644 --- a/src/MongoDB.Bson/ObjectModel/Decimal128.cs +++ b/src/MongoDB.Bson/ObjectModel/Decimal128.cs @@ -1523,6 +1523,25 @@ public Decimal128(Half value) } #endif + /// + /// Initializes a new instance of the struct. + /// + /// The value. + [CLSCompliant(false)] + public Decimal128(sbyte value) + { + if (value >= 0) + { + _highBits = 0; + _lowBits = (ulong)value; + } + else + { + _highBits = Flags.SignBit; + _lowBits = value == sbyte.MinValue ? (ulong)sbyte.MaxValue + 1 : (ulong)-value; + } + } + /// /// Initializes a new instance of the struct. /// @@ -1559,6 +1578,16 @@ public Decimal128(long value) } } + /// + /// Initializes a new instance of the struct. + /// + /// The value. + public Decimal128(byte value) + { + _highBits = 0; + _lowBits = value; + } + /// /// Initializes a new instance of the struct. ///