private object SmallestNumeric(object constant)
{
if (null == constant)
{
return 0;
}
else
{
string sval = (constant as string);
if (null != sval)
{
int i4;
if (int.TryParse(sval, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i4))
{
return i4;
}
long i8;
if (long.TryParse(sval, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i8))
{
return i8;
}
double r8;
if (double.TryParse(sval, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.InvariantInfo, out r8))
{
return r8;
}
}
else
{
IConvertible convertible = (constant as IConvertible);
if (null != convertible)
{
try
{
return convertible.ToInt32(NumberFormatInfo.InvariantInfo);
}
catch (System.ArgumentException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.FormatException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.InvalidCastException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.OverflowException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
try
{
return convertible.ToInt64(NumberFormatInfo.InvariantInfo);
}
catch (System.ArgumentException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.FormatException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.InvalidCastException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.OverflowException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
try
{
return convertible.ToDouble(NumberFormatInfo.InvariantInfo);
}
catch (System.ArgumentException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.FormatException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.InvalidCastException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
catch (System.OverflowException e)
{
ExceptionBuilder.TraceExceptionWithoutRethrow(e);
}
}
}
}
return constant;
}
}