For some context, the record class SaleAmount property is
public decimal? SaleAmount
{
get;
set;
}
Ideally I would go with this
record.SaleAmount.Value =
sql.Reader.IsDBNull(IDX_SALEAMOUNT) ? null :
sql.Reader.GetDecimal(IDX_SALEAMOUNT);
Alas the compiler and this are not friends because…
Type of conditional expression cannot be determined because there is no implicit conversion between ” and ‘decimal’
So how would you express this elegantly, and dont play the obvious card like below…
if (!sql.Reader.IsDBNull(IDX_SALEAMOUNT))
record.SaleAmount = sql.Reader.GetDecimal(IDX_SALEAMOUNT);
Or is above the best solution?
If you’re using C# 3, I’d actually make this easier for yourself using an extension method:
Then your application code can just use: