public static decimal DecodeDecimal(object value, int scale, int sqltype) { var shift = scale < 0 ? -scale : 1; switch (sqltype & ~1) { case IscCodes.SQL_SHORT: return(DecimalShiftHelper.ShiftDecimalLeft((decimal)(short)value, shift)); case IscCodes.SQL_LONG: return(DecimalShiftHelper.ShiftDecimalLeft((decimal)(int)value, shift)); case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: return(DecimalShiftHelper.ShiftDecimalLeft((decimal)(long)value, shift)); case IscCodes.SQL_DOUBLE: case IscCodes.SQL_D_FLOAT: return((decimal)(double)value); case IscCodes.SQL_INT128: return(DecimalShiftHelper.ShiftDecimalLeft((decimal)(BigInteger)value, shift)); default: throw new ArgumentOutOfRangeException(nameof(sqltype), $"{nameof(sqltype)}={sqltype}"); } }
public static object EncodeDecimal(decimal d, int scale, int sqltype) { var shift = scale < 0 ? -scale : scale; switch (sqltype & ~1) { case IscCodes.SQL_SHORT: return((short)DecimalShiftHelper.ShiftDecimalRight(d, shift)); case IscCodes.SQL_LONG: return((int)DecimalShiftHelper.ShiftDecimalRight(d, shift)); case IscCodes.SQL_QUAD: case IscCodes.SQL_INT64: return((long)DecimalShiftHelper.ShiftDecimalRight(d, shift)); case IscCodes.SQL_DOUBLE: case IscCodes.SQL_D_FLOAT: return((double)d); case IscCodes.SQL_INT128: return((BigInteger)DecimalShiftHelper.ShiftDecimalRight(d, shift)); default: throw new ArgumentOutOfRangeException(nameof(sqltype), $"{nameof(sqltype)}={sqltype}"); } }