I have a simple table with a nullable numeric field JOB_TYPE, which BOM sees as a System.Decimal value. If I set BOM to use "Nullable Generics" AND to create property accessing event for the field, I get the following BOM-generated code for the field accessor
public Nullable<System.Decimal> JOB_TYPE
{
get
{
object loValue;
PeopleBOFieldAccessingEventArgs e;
Nullable<System.Decimal> loReturn;
loValue = this.CurrentRow["JOB_TYPE"];
if (loValue == DBNull.Value)
{
loReturn = (Nullable<System.Decimal> )null;
}
else
{
loReturn = new Nullable<System.Decimal> ((System.Decimal)loValue);
}
e = new PeopleBOFieldAccessingEventArgs(PeopleBOFieldNames.JOB_TYPE, loReturn);
this.OnFieldPropertyAccessing(this, e);
return new Nullable<System.Decimal> ((System.Decimal)(e.ValueToReturn)); <===BOOM!
}
set
{...}
If JOB_TYPE is null, loReturn becomes a null of type decimal?, but is cast (boxed) into a null of type object for the eventargs. After the event is processed (there is no code in the event itself), the value of e.ValueToReturn is a null of type object, which causes the exception when attempting the cast to System.Decimal.
If this a "bug" or "feature"?