Skip to content

Commit

Permalink
Revert "CSHARP-4566: Support widening numeric and nullable-numeric co…
Browse files Browse the repository at this point in the history
…nversions."

This reverts commit e9d6231.
  • Loading branch information
rstam committed Oct 6, 2023
1 parent 82c573b commit ca09e64
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 2,452 deletions.
35 changes: 0 additions & 35 deletions src/MongoDB.Bson/Serialization/IBsonNumericSerializer.cs

This file was deleted.

161 changes: 1 addition & 160 deletions src/MongoDB.Bson/Serialization/Options/RepresentationConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

using System;
using MongoDB.Bson.Serialization.Attributes;

namespace MongoDB.Bson.Serialization.Options
{
Expand Down Expand Up @@ -56,70 +57,6 @@ public bool AllowTruncation
}

// public methods
/// <summary>
/// Converts an Int32 to a byte.
/// </summary>
/// <param name="value">An Int32.</param>
/// <returns>A byte.</returns>
public byte ToByte(int value)
{
if (value < byte.MinValue || value > byte.MaxValue)
{
if (!_allowOverflow) { throw new OverflowException(); }
return unchecked((byte)value);
}

return checked((byte)value);
}

/// <summary>
/// Converts an Int64 to a byte.
/// </summary>
/// <param name="value">An Int64.</param>
/// <returns>A byte.</returns>
public byte ToByte(long value)
{
if (value < byte.MinValue || value > byte.MaxValue)
{
if (!_allowOverflow) { throw new OverflowException(); }
return unchecked((byte)value);
}

return checked((byte)value);
}

/// <summary>
/// Converts an Int32 to a char.
/// </summary>
/// <param name="value">An Int32.</param>
/// <returns>A char.</returns>
public char ToChar(int value)
{
if (value < char.MinValue || value > char.MaxValue)
{
if (!_allowOverflow) { throw new OverflowException(); }
return unchecked((char)value);
}

return checked((char)value);
}

/// <summary>
/// Converts an Int64 to a char.
/// </summary>
/// <param name="value">An Int64.</param>
/// <returns>A char.</returns>
public char ToChar(long value)
{
if (value < char.MinValue || value > char.MaxValue)
{
if (!_allowOverflow) { throw new OverflowException(); }
return unchecked((char)value);
}

return checked((char)value);
}

/// <summary>
/// Converts a Decimal128 to a Decimal.
/// </summary>
Expand Down Expand Up @@ -548,26 +485,6 @@ public short ToInt16(long value)
return (short)value;
}

/// <summary>
/// Converts a byte to an Int32.
/// </summary>
/// <param name="value">A byte.</param>
/// <returns>An Int32.</returns>
public int ToInt32(byte value)
{
return (int)value;
}

/// <summary>
/// Converts a char to an Int32.
/// </summary>
/// <param name="value">A char.</param>
/// <returns>An Int32.</returns>
public int ToInt32(char value)
{
return (int)value;
}

/// <summary>
/// Converts a Decimal to an Int32.
/// </summary>
Expand Down Expand Up @@ -681,17 +598,6 @@ public int ToInt32(long value)
return (int)value;
}

/// <summary>
/// Converts an sbyte to an Int32.
/// </summary>
/// <param name="value">An sbyte.</param>
/// <returns>An Int32.</returns>
[CLSCompliant(false)]
public int ToInt32(sbyte value)
{
return (int)value;
}

/// <summary>
/// Converts an Int16 to an Int32.
/// </summary>
Expand Down Expand Up @@ -743,26 +649,6 @@ public int ToInt32(ushort value)
return value;
}

/// <summary>
/// Converts a byte to an Int64.
/// </summary>
/// <param name="value">A byte.</param>
/// <returns>An Int64.</returns>
public long ToInt64(byte value)
{
return (long)value;
}

/// <summary>
/// Converts a char to an Int64.
/// </summary>
/// <param name="value">A char.</param>
/// <returns>An Int64.</returns>
public long ToInt64(char value)
{
return (long)value;
}

/// <summary>
/// Converts a Decimal to an Int64.
/// </summary>
Expand Down Expand Up @@ -872,17 +758,6 @@ public long ToInt64(long value)
return value;
}

/// <summary>
/// Converts an sbyte to an Int64.
/// </summary>
/// <param name="value">An sbyte.</param>
/// <returns>An Int64.</returns>
[CLSCompliant(false)]
public long ToInt64(sbyte value)
{
return (long)value;
}

/// <summary>
/// Converts an Int16 to an Int64.
/// </summary>
Expand Down Expand Up @@ -930,40 +805,6 @@ public long ToInt64(ushort value)
return value;
}

/// <summary>
/// Converts an Int32 to an sbyte.
/// </summary>
/// <param name="value">An Int32.</param>
/// <returns>An sbyte.</returns>
[CLSCompliant(false)]
public sbyte ToSByte(int value)
{
if (value < sbyte.MinValue || value > sbyte.MaxValue)
{
if (!_allowOverflow) { throw new OverflowException(); }
return unchecked((sbyte)value);
}

return checked((sbyte)value);
}

/// <summary>
/// Converts an Int64 to an sbyte.
/// </summary>
/// <param name="value">An Int64.</param>
/// <returns>An sbyte.</returns>
[CLSCompliant(false)]
public sbyte ToSByte(long value)
{
if (value < sbyte.MinValue || value > sbyte.MaxValue)
{
if (!_allowOverflow) { throw new OverflowException(); }
return unchecked((sbyte)value);
}

return checked((sbyte)value);
}

/// <summary>
/// Converts a Decimal128 to a Single.
/// </summary>
Expand Down
Loading

0 comments on commit ca09e64

Please sign in to comment.