This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new e24cba1  AVRO-3314 Updated exception thrown by IConvertable.ToType 
(#1467)
e24cba1 is described below

commit e24cba1d4ce35696c998a5508aaede687421ff89
Author: Kyle Schoonover <[email protected]>
AuthorDate: Mon Jan 24 00:51:07 2022 -0800

    AVRO-3314 Updated exception thrown by IConvertable.ToType (#1467)
    
    Co-authored-by: Kyle T. Schoonover <[email protected]>
    (cherry picked from commit 8a06ea3107664bc0083883459e4d4839ab7dd6b4)
---
 lang/csharp/src/apache/main/AvroDecimal.cs | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/lang/csharp/src/apache/main/AvroDecimal.cs 
b/lang/csharp/src/apache/main/AvroDecimal.cs
index 17d1120..5462914 100644
--- a/lang/csharp/src/apache/main/AvroDecimal.cs
+++ b/lang/csharp/src/apache/main/AvroDecimal.cs
@@ -25,8 +25,8 @@ namespace Avro
     /// <summary>
     /// Represents a big decimal.
     /// </summary>
-    #pragma warning disable CS1591 // Missing XML comment for publicly visible 
type or member
-    #pragma warning disable CA2225 // Operator overloads have named alternates
+#pragma warning disable CS1591 // Missing XML comment for publicly visible 
type or member
+#pragma warning disable CA2225 // Operator overloads have named alternates
     public struct AvroDecimal : IConvertible, IFormattable, IComparable, 
IComparable<AvroDecimal>, IEquatable<AvroDecimal>
     {
         /// <summary>
@@ -470,7 +470,7 @@ namespace Avro
         public static implicit operator AvroDecimal(BigInteger value)
         {
             return new AvroDecimal(value, 0);
-        } 
+        }
 
         /// <summary>
         /// Converts the numeric value of the current <see 
cref="AvroDecimal"/> to a given type.
@@ -484,19 +484,24 @@ namespace Avro
         }
 
         /// <summary>
-        /// Converts the numeric value of the current <see 
cref="AvroDecimal"/> to a given type.
+        /// Converts the numeric value of the current <see cref="AvroDecimal" 
/> to a given type.
         /// </summary>
-        /// <param name="conversionType">The type to which the value of the 
current <see cref="AvroDecimal"/> should be converted.</param>
+        /// <param name="conversionType">The type to which the value of the 
current <see cref="AvroDecimal" /> should be converted.</param>
         /// <param name="provider">An System.IFormatProvider interface 
implementation that supplies culture-specific formatting information.</param>
-        /// <returns></returns>
+        /// <returns>
+        /// An <see cref="T:System.Object"></see> instance of type <paramref 
name="conversionType">conversionType</paramref> whose value is equivalent to 
the value of this instance.
+        /// </returns>
+        /// <exception cref="System.OverflowException">The value 
{UnscaledValue} cannot fit into {conversionType.Name}.</exception>
         object IConvertible.ToType(Type conversionType, IFormatProvider 
provider)
         {
             var scaleDivisor = BigInteger.Pow(new BigInteger(10), Scale);
             var remainder = BigInteger.Remainder(UnscaledValue, scaleDivisor);
             var scaledValue = BigInteger.Divide(UnscaledValue, scaleDivisor);
 
-            if (scaledValue > new BigInteger(Decimal.MaxValue))
-                throw new ArgumentOutOfRangeException("value", "The value " + 
UnscaledValue + " cannot fit into " + conversionType.Name + ".");
+            if (scaledValue > new BigInteger(decimal.MaxValue))
+            {
+                throw new OverflowException($"The value {UnscaledValue} cannot 
fit into {conversionType.Name}.");
+            }
 
             var leftOfDecimal = (decimal)scaledValue;
             var rightOfDecimal = ((decimal)remainder) / 
((decimal)scaleDivisor);
@@ -781,6 +786,6 @@ namespace Avro
             return bytes;
         }
     }
-    #pragma warning restore CA2225 // Operator overloads have named alternates
-    #pragma warning restore CS1591 // Missing XML comment for publicly visible 
type or member
+#pragma warning restore CA2225 // Operator overloads have named alternates
+#pragma warning restore CS1591 // Missing XML comment for publicly visible 
type or member
 }

Reply via email to