This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
GradeCalc/GradeCalc/NCalcDoubleParser.cs

36 lines
1.4 KiB
C#
Raw Normal View History

2019-12-01 19:33:28 +01:00
using System;
namespace GradeCalc
{
2020-02-29 13:20:21 +01:00
internal static class NCalcDoubleParser
2019-12-01 19:33:28 +01:00
{
public static double Parse(object NCalcOutput)
{
if (NCalcOutput.GetType() == typeof(bool))
2020-02-29 13:20:21 +01:00
return (bool) NCalcOutput ? 1 : 0;
if (NCalcOutput.GetType() == typeof(byte))
return (byte) NCalcOutput;
if (NCalcOutput.GetType() == typeof(sbyte))
return (sbyte) NCalcOutput;
if (NCalcOutput.GetType() == typeof(short))
return (short) NCalcOutput;
if (NCalcOutput.GetType() == typeof(ushort))
return (ushort) NCalcOutput;
if (NCalcOutput.GetType() == typeof(int))
return (int) NCalcOutput;
if (NCalcOutput.GetType() == typeof(uint))
return (uint) NCalcOutput;
if (NCalcOutput.GetType() == typeof(long))
return (long) NCalcOutput;
if (NCalcOutput.GetType() == typeof(ulong))
return (ulong) NCalcOutput;
if (NCalcOutput.GetType() == typeof(float))
return (float) NCalcOutput;
if (NCalcOutput.GetType() == typeof(double))
return (double) NCalcOutput;
if (NCalcOutput.GetType() == typeof(decimal))
return (double) (decimal) NCalcOutput;
throw new ArgumentException("Type mismatch! (" + NCalcOutput.GetType() + ")");
2019-12-01 19:33:28 +01:00
}
}
2020-02-29 13:20:21 +01:00
}