I'm currently working on an application where I need to load data from an SQL database and then assign the resulting values to the properties of the object. I do this using reflection, as the property names and column names are the same. However, many properties use their own type of structure, which basically represents the shell of the currency for the decimal type. I defined an implicit conversion in my structure:
public static implicit operator Currency(decimal d)
{
return new Currency(d);
}
This works great when I use it in code. However, when I have this:
foreach (PropertyInfo p in props)
{
p.SetValue(this, table.Rows[0][p.Name], null);
}
It throws an ArgumentException, which states that it cannot convert from System.Decimal to Currency. I am confused as it works great in any other circumstances.