Skip to content

Commit ca09e64

Browse files
committed
Revert "CSHARP-4566: Support widening numeric and nullable-numeric conversions."
This reverts commit e9d6231.
1 parent 82c573b commit ca09e64

24 files changed

+167
-2452
lines changed

src/MongoDB.Bson/Serialization/IBsonNumericSerializer.cs

-35
This file was deleted.

src/MongoDB.Bson/Serialization/Options/RepresentationConverter.cs

+1-160
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System;
17+
using MongoDB.Bson.Serialization.Attributes;
1718

1819
namespace MongoDB.Bson.Serialization.Options
1920
{
@@ -56,70 +57,6 @@ public bool AllowTruncation
5657
}
5758

5859
// public methods
59-
/// <summary>
60-
/// Converts an Int32 to a byte.
61-
/// </summary>
62-
/// <param name="value">An Int32.</param>
63-
/// <returns>A byte.</returns>
64-
public byte ToByte(int value)
65-
{
66-
if (value < byte.MinValue || value > byte.MaxValue)
67-
{
68-
if (!_allowOverflow) { throw new OverflowException(); }
69-
return unchecked((byte)value);
70-
}
71-
72-
return checked((byte)value);
73-
}
74-
75-
/// <summary>
76-
/// Converts an Int64 to a byte.
77-
/// </summary>
78-
/// <param name="value">An Int64.</param>
79-
/// <returns>A byte.</returns>
80-
public byte ToByte(long value)
81-
{
82-
if (value < byte.MinValue || value > byte.MaxValue)
83-
{
84-
if (!_allowOverflow) { throw new OverflowException(); }
85-
return unchecked((byte)value);
86-
}
87-
88-
return checked((byte)value);
89-
}
90-
91-
/// <summary>
92-
/// Converts an Int32 to a char.
93-
/// </summary>
94-
/// <param name="value">An Int32.</param>
95-
/// <returns>A char.</returns>
96-
public char ToChar(int value)
97-
{
98-
if (value < char.MinValue || value > char.MaxValue)
99-
{
100-
if (!_allowOverflow) { throw new OverflowException(); }
101-
return unchecked((char)value);
102-
}
103-
104-
return checked((char)value);
105-
}
106-
107-
/// <summary>
108-
/// Converts an Int64 to a char.
109-
/// </summary>
110-
/// <param name="value">An Int64.</param>
111-
/// <returns>A char.</returns>
112-
public char ToChar(long value)
113-
{
114-
if (value < char.MinValue || value > char.MaxValue)
115-
{
116-
if (!_allowOverflow) { throw new OverflowException(); }
117-
return unchecked((char)value);
118-
}
119-
120-
return checked((char)value);
121-
}
122-
12360
/// <summary>
12461
/// Converts a Decimal128 to a Decimal.
12562
/// </summary>
@@ -548,26 +485,6 @@ public short ToInt16(long value)
548485
return (short)value;
549486
}
550487

551-
/// <summary>
552-
/// Converts a byte to an Int32.
553-
/// </summary>
554-
/// <param name="value">A byte.</param>
555-
/// <returns>An Int32.</returns>
556-
public int ToInt32(byte value)
557-
{
558-
return (int)value;
559-
}
560-
561-
/// <summary>
562-
/// Converts a char to an Int32.
563-
/// </summary>
564-
/// <param name="value">A char.</param>
565-
/// <returns>An Int32.</returns>
566-
public int ToInt32(char value)
567-
{
568-
return (int)value;
569-
}
570-
571488
/// <summary>
572489
/// Converts a Decimal to an Int32.
573490
/// </summary>
@@ -681,17 +598,6 @@ public int ToInt32(long value)
681598
return (int)value;
682599
}
683600

684-
/// <summary>
685-
/// Converts an sbyte to an Int32.
686-
/// </summary>
687-
/// <param name="value">An sbyte.</param>
688-
/// <returns>An Int32.</returns>
689-
[CLSCompliant(false)]
690-
public int ToInt32(sbyte value)
691-
{
692-
return (int)value;
693-
}
694-
695601
/// <summary>
696602
/// Converts an Int16 to an Int32.
697603
/// </summary>
@@ -743,26 +649,6 @@ public int ToInt32(ushort value)
743649
return value;
744650
}
745651

746-
/// <summary>
747-
/// Converts a byte to an Int64.
748-
/// </summary>
749-
/// <param name="value">A byte.</param>
750-
/// <returns>An Int64.</returns>
751-
public long ToInt64(byte value)
752-
{
753-
return (long)value;
754-
}
755-
756-
/// <summary>
757-
/// Converts a char to an Int64.
758-
/// </summary>
759-
/// <param name="value">A char.</param>
760-
/// <returns>An Int64.</returns>
761-
public long ToInt64(char value)
762-
{
763-
return (long)value;
764-
}
765-
766652
/// <summary>
767653
/// Converts a Decimal to an Int64.
768654
/// </summary>
@@ -872,17 +758,6 @@ public long ToInt64(long value)
872758
return value;
873759
}
874760

875-
/// <summary>
876-
/// Converts an sbyte to an Int64.
877-
/// </summary>
878-
/// <param name="value">An sbyte.</param>
879-
/// <returns>An Int64.</returns>
880-
[CLSCompliant(false)]
881-
public long ToInt64(sbyte value)
882-
{
883-
return (long)value;
884-
}
885-
886761
/// <summary>
887762
/// Converts an Int16 to an Int64.
888763
/// </summary>
@@ -930,40 +805,6 @@ public long ToInt64(ushort value)
930805
return value;
931806
}
932807

933-
/// <summary>
934-
/// Converts an Int32 to an sbyte.
935-
/// </summary>
936-
/// <param name="value">An Int32.</param>
937-
/// <returns>An sbyte.</returns>
938-
[CLSCompliant(false)]
939-
public sbyte ToSByte(int value)
940-
{
941-
if (value < sbyte.MinValue || value > sbyte.MaxValue)
942-
{
943-
if (!_allowOverflow) { throw new OverflowException(); }
944-
return unchecked((sbyte)value);
945-
}
946-
947-
return checked((sbyte)value);
948-
}
949-
950-
/// <summary>
951-
/// Converts an Int64 to an sbyte.
952-
/// </summary>
953-
/// <param name="value">An Int64.</param>
954-
/// <returns>An sbyte.</returns>
955-
[CLSCompliant(false)]
956-
public sbyte ToSByte(long value)
957-
{
958-
if (value < sbyte.MinValue || value > sbyte.MaxValue)
959-
{
960-
if (!_allowOverflow) { throw new OverflowException(); }
961-
return unchecked((sbyte)value);
962-
}
963-
964-
return checked((sbyte)value);
965-
}
966-
967808
/// <summary>
968809
/// Converts a Decimal128 to a Single.
969810
/// </summary>

0 commit comments

Comments
 (0)