public static object ConvertFromReturnCode(this string returnCode, Type destinationType)
{
if (destinationType == typeof(int))
{
return Convert.ToInt32(returnCode);
}
if (destinationType == typeof(short))
{
return Convert.ToInt16(returnCode);
}
if (destinationType == typeof(long))
{
return Convert.ToInt64(returnCode);
}
if (destinationType.IsEnum())
{
return Enum.Parse(destinationType, returnCode);
}
throw new ArgumentException("The return code can only be an enum or an integer.", nameof(destinationType));
}
}