private void WriteSqlMoney(SqlMoney value, int length, TdsParserStateObject stateObj)
{
int[] bits = Decimal.GetBits(value.Value);
// this decimal should be scaled by 10000 (regardless of what the incoming decimal was scaled by)
bool isNeg = (0 != (bits[3] & unchecked((int)0x80000000)));
long l = ((long)(uint)bits[1]) << 0x20 | (uint)bits[0];
if (isNeg)
l = -l;
if (length == 4)
{
Decimal decimalValue = value.Value;
// validate the value can be represented as a small money
if (decimalValue < TdsEnums.SQL_SMALL_MONEY_MIN || decimalValue > TdsEnums.SQL_SMALL_MONEY_MAX)
{
throw SQL.MoneyOverflow(decimalValue.ToString(CultureInfo.InvariantCulture));
}
WriteInt((int)l, stateObj);
}
else
{
WriteInt((int)(l >> 0x20), stateObj);
WriteInt((int)l, stateObj);
}
}