Skip to content

Commit baf69de

Browse files
committed
Removing the static virtual declarations since things are falling over
1 parent 8ab8539 commit baf69de

File tree

23 files changed

+1519
-57
lines changed

23 files changed

+1519
-57
lines changed

src/libraries/System.Private.CoreLib/src/System/Byte.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,76 @@ bool IBinaryInteger<byte>.TryWriteLittleEndian(Span<byte> destination, out int b
531531
/// <inheritdoc cref="INumberBase{TSelf}.Abs(TSelf)" />
532532
static byte INumberBase<byte>.Abs(byte value) => value;
533533

534+
/// <summary>Creates an instance of the current type from a value, throwing an overflow exception for any values that fall outside the representable range of the current type.</summary>
535+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
536+
/// <param name="value">The value which is used to create the instance of <see cref="byte" />.</param>
537+
/// <returns>An instance of <see cref="byte" /> created from <paramref name="value" />.</returns>
538+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
539+
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="byte" />.</exception>
540+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
541+
public static byte CreateChecked<TOther>(TOther value)
542+
where TOther : INumberBase<TOther>
543+
{
544+
byte result;
545+
546+
if (typeof(TOther) == typeof(byte))
547+
{
548+
result = (byte)(object)value;
549+
}
550+
else if (!NumberBase<byte>.TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result))
551+
{
552+
ThrowHelper.ThrowNotSupportedException();
553+
}
554+
555+
return result;
556+
}
557+
558+
/// <summary>Creates an instance of the current type from a value, saturating any values that fall outside the representable range of the current type.</summary>
559+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
560+
/// <param name="value">The value which is used to create the instance of <see cref="byte" />.</param>
561+
/// <returns>An instance of <see cref="byte" /> created from <paramref name="value" />, saturating if <paramref name="value" /> falls outside the representable range of <see cref="byte" />.</returns>
562+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
563+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
564+
public static byte CreateSaturating<TOther>(TOther value)
565+
where TOther : INumberBase<TOther>
566+
{
567+
byte result;
568+
569+
if (typeof(TOther) == typeof(byte))
570+
{
571+
result = (byte)(object)value;
572+
}
573+
else if (!NumberBase<byte>.TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result))
574+
{
575+
ThrowHelper.ThrowNotSupportedException();
576+
}
577+
578+
return result;
579+
}
580+
581+
/// <summary>Creates an instance of the current type from a value, truncating any values that fall outside the representable range of the current type.</summary>
582+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
583+
/// <param name="value">The value which is used to create the instance of <see cref="byte" />.</param>
584+
/// <returns>An instance of <see cref="byte" /> created from <paramref name="value" />, truncating if <paramref name="value" /> falls outside the representable range of <see cref="byte" />.</returns>
585+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
586+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
587+
public static byte CreateTruncating<TOther>(TOther value)
588+
where TOther : INumberBase<TOther>
589+
{
590+
byte result;
591+
592+
if (typeof(TOther) == typeof(byte))
593+
{
594+
result = (byte)(object)value;
595+
}
596+
else if (!NumberBase<byte>.TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result))
597+
{
598+
ThrowHelper.ThrowNotSupportedException();
599+
}
600+
601+
return result;
602+
}
603+
534604
/// <inheritdoc cref="INumberBase{TSelf}.IsCanonical(TSelf)" />
535605
static bool INumberBase<byte>.IsCanonical(byte value) => true;
536606

src/libraries/System.Private.CoreLib/src/System/Char.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,76 @@ bool IBinaryInteger<char>.TryWriteLittleEndian(Span<byte> destination, out int b
13821382
/// <inheritdoc cref="INumberBase{TSelf}.Abs(TSelf)" />
13831383
static char INumberBase<char>.Abs(char value) => value;
13841384

1385+
/// <summary>Creates an instance of the current type from a value, throwing an overflow exception for any values that fall outside the representable range of the current type.</summary>
1386+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1387+
/// <param name="value">The value which is used to create the instance of <see cref="char" />.</param>
1388+
/// <returns>An instance of <see cref="char" /> created from <paramref name="value" />.</returns>
1389+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1390+
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="char" />.</exception>
1391+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1392+
public static char CreateChecked<TOther>(TOther value)
1393+
where TOther : INumberBase<TOther>
1394+
{
1395+
char result;
1396+
1397+
if (typeof(TOther) == typeof(char))
1398+
{
1399+
result = (char)(object)value;
1400+
}
1401+
else if (!NumberBase<char>.TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result))
1402+
{
1403+
ThrowHelper.ThrowNotSupportedException();
1404+
}
1405+
1406+
return result;
1407+
}
1408+
1409+
/// <summary>Creates an instance of the current type from a value, saturating any values that fall outside the representable range of the current type.</summary>
1410+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1411+
/// <param name="value">The value which is used to create the instance of <see cref="char" />.</param>
1412+
/// <returns>An instance of <see cref="char" /> created from <paramref name="value" />, saturating if <paramref name="value" /> falls outside the representable range of <see cref="char" />.</returns>
1413+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1414+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1415+
public static char CreateSaturating<TOther>(TOther value)
1416+
where TOther : INumberBase<TOther>
1417+
{
1418+
char result;
1419+
1420+
if (typeof(TOther) == typeof(char))
1421+
{
1422+
result = (char)(object)value;
1423+
}
1424+
else if (!NumberBase<char>.TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result))
1425+
{
1426+
ThrowHelper.ThrowNotSupportedException();
1427+
}
1428+
1429+
return result;
1430+
}
1431+
1432+
/// <summary>Creates an instance of the current type from a value, truncating any values that fall outside the representable range of the current type.</summary>
1433+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1434+
/// <param name="value">The value which is used to create the instance of <see cref="char" />.</param>
1435+
/// <returns>An instance of <see cref="char" /> created from <paramref name="value" />, truncating if <paramref name="value" /> falls outside the representable range of <see cref="char" />.</returns>
1436+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1437+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1438+
public static char CreateTruncating<TOther>(TOther value)
1439+
where TOther : INumberBase<TOther>
1440+
{
1441+
char result;
1442+
1443+
if (typeof(TOther) == typeof(char))
1444+
{
1445+
result = (char)(object)value;
1446+
}
1447+
else if (!NumberBase<char>.TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result))
1448+
{
1449+
ThrowHelper.ThrowNotSupportedException();
1450+
}
1451+
1452+
return result;
1453+
}
1454+
13851455
/// <inheritdoc cref="INumberBase{TSelf}.IsCanonical(TSelf)" />
13861456
static bool INumberBase<char>.IsCanonical(char value) => true;
13871457

src/libraries/System.Private.CoreLib/src/System/Decimal.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,76 @@ public static decimal Abs(decimal value)
13441344
return new decimal(in value, value._flags & ~SignMask);
13451345
}
13461346

1347+
/// <summary>Creates an instance of the current type from a value, throwing an overflow exception for any values that fall outside the representable range of the current type.</summary>
1348+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1349+
/// <param name="value">The value which is used to create the instance of <see cref="decimal" />.</param>
1350+
/// <returns>An instance of <see cref="decimal" /> created from <paramref name="value" />.</returns>
1351+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1352+
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="decimal" />.</exception>
1353+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1354+
public static decimal CreateChecked<TOther>(TOther value)
1355+
where TOther : INumberBase<TOther>
1356+
{
1357+
decimal result;
1358+
1359+
if (typeof(TOther) == typeof(decimal))
1360+
{
1361+
result = (decimal)(object)value;
1362+
}
1363+
else if (!NumberBase<decimal>.TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result))
1364+
{
1365+
ThrowHelper.ThrowNotSupportedException();
1366+
}
1367+
1368+
return result;
1369+
}
1370+
1371+
/// <summary>Creates an instance of the current type from a value, saturating any values that fall outside the representable range of the current type.</summary>
1372+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1373+
/// <param name="value">The value which is used to create the instance of <see cref="decimal" />.</param>
1374+
/// <returns>An instance of <see cref="decimal" /> created from <paramref name="value" />, saturating if <paramref name="value" /> falls outside the representable range of <see cref="decimal" />.</returns>
1375+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1376+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1377+
public static decimal CreateSaturating<TOther>(TOther value)
1378+
where TOther : INumberBase<TOther>
1379+
{
1380+
decimal result;
1381+
1382+
if (typeof(TOther) == typeof(decimal))
1383+
{
1384+
result = (decimal)(object)value;
1385+
}
1386+
else if (!NumberBase<decimal>.TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result))
1387+
{
1388+
ThrowHelper.ThrowNotSupportedException();
1389+
}
1390+
1391+
return result;
1392+
}
1393+
1394+
/// <summary>Creates an instance of the current type from a value, truncating any values that fall outside the representable range of the current type.</summary>
1395+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1396+
/// <param name="value">The value which is used to create the instance of <see cref="decimal" />.</param>
1397+
/// <returns>An instance of <see cref="decimal" /> created from <paramref name="value" />, truncating if <paramref name="value" /> falls outside the representable range of <see cref="decimal" />.</returns>
1398+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1399+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1400+
public static decimal CreateTruncating<TOther>(TOther value)
1401+
where TOther : INumberBase<TOther>
1402+
{
1403+
decimal result;
1404+
1405+
if (typeof(TOther) == typeof(decimal))
1406+
{
1407+
result = (decimal)(object)value;
1408+
}
1409+
else if (!NumberBase<decimal>.TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result))
1410+
{
1411+
ThrowHelper.ThrowNotSupportedException();
1412+
}
1413+
1414+
return result;
1415+
}
1416+
13471417
/// <inheritdoc cref="INumberBase{TSelf}.IsCanonical(TSelf)" />
13481418
public static bool IsCanonical(decimal value)
13491419
{

src/libraries/System.Private.CoreLib/src/System/Double.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,76 @@ public static double MinNumber(double x, double y)
10031003
/// <inheritdoc cref="INumberBase{TSelf}.Abs(TSelf)" />
10041004
public static double Abs(double value) => Math.Abs(value);
10051005

1006+
/// <summary>Creates an instance of the current type from a value, throwing an overflow exception for any values that fall outside the representable range of the current type.</summary>
1007+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1008+
/// <param name="value">The value which is used to create the instance of <see cref="double" />.</param>
1009+
/// <returns>An instance of <see cref="double" /> created from <paramref name="value" />.</returns>
1010+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1011+
/// <exception cref="OverflowException"><paramref name="value" /> is not representable by <see cref="double" />.</exception>
1012+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1013+
public static double CreateChecked<TOther>(TOther value)
1014+
where TOther : INumberBase<TOther>
1015+
{
1016+
double result;
1017+
1018+
if (typeof(TOther) == typeof(double))
1019+
{
1020+
result = (double)(object)value;
1021+
}
1022+
else if (!NumberBase<double>.TryConvertFromChecked(value, out result) && !TOther.TryConvertToChecked(value, out result))
1023+
{
1024+
ThrowHelper.ThrowNotSupportedException();
1025+
}
1026+
1027+
return result;
1028+
}
1029+
1030+
/// <summary>Creates an instance of the current type from a value, saturating any values that fall outside the representable range of the current type.</summary>
1031+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1032+
/// <param name="value">The value which is used to create the instance of <see cref="double" />.</param>
1033+
/// <returns>An instance of <see cref="double" /> created from <paramref name="value" />, saturating if <paramref name="value" /> falls outside the representable range of <see cref="double" />.</returns>
1034+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1035+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1036+
public static double CreateSaturating<TOther>(TOther value)
1037+
where TOther : INumberBase<TOther>
1038+
{
1039+
double result;
1040+
1041+
if (typeof(TOther) == typeof(double))
1042+
{
1043+
result = (double)(object)value;
1044+
}
1045+
else if (!NumberBase<double>.TryConvertFromSaturating(value, out result) && !TOther.TryConvertToSaturating(value, out result))
1046+
{
1047+
ThrowHelper.ThrowNotSupportedException();
1048+
}
1049+
1050+
return result;
1051+
}
1052+
1053+
/// <summary>Creates an instance of the current type from a value, truncating any values that fall outside the representable range of the current type.</summary>
1054+
/// <typeparam name="TOther">The type of <paramref name="value" />.</typeparam>
1055+
/// <param name="value">The value which is used to create the instance of <see cref="double" />.</param>
1056+
/// <returns>An instance of <see cref="double" /> created from <paramref name="value" />, truncating if <paramref name="value" /> falls outside the representable range of <see cref="double" />.</returns>
1057+
/// <exception cref="NotSupportedException"><typeparamref name="TOther" /> is not supported.</exception>
1058+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1059+
public static double CreateTruncating<TOther>(TOther value)
1060+
where TOther : INumberBase<TOther>
1061+
{
1062+
double result;
1063+
1064+
if (typeof(TOther) == typeof(double))
1065+
{
1066+
result = (double)(object)value;
1067+
}
1068+
else if (!NumberBase<double>.TryConvertFromTruncating(value, out result) && !TOther.TryConvertToTruncating(value, out result))
1069+
{
1070+
ThrowHelper.ThrowNotSupportedException();
1071+
}
1072+
1073+
return result;
1074+
}
1075+
10061076
/// <inheritdoc cref="INumberBase{TSelf}.IsCanonical(TSelf)" />
10071077
static bool INumberBase<double>.IsCanonical(double value) => true;
10081078

0 commit comments

Comments
 (0)