The code below runs fine on .Net 3.5:
PropertyInfo propertyInfo = typeof(int?).GetProperty("Value");
int? i = 5;
object o = propertyInfo.GetValue(i, null);
After running, o
is of type int
and has the value 5
. Which is OK.
When I run the same code on .Net Compact Framework 3.5, I get an InvalidProgramException
on the last line.
- Why does that happen?
- Is there anything I can do about it?
- Is this a bug in .Net CF?
What I am doing currently is determining whether the Type
I am dealing with is a System.Nullable<T>
and the property I am getting has the name "Value"
and then handle that case explicitly. But I would like to know whether there is a more simple solution.
The code I am writing parses an expression tree (we use a mono dll that implements System.Linq.Expressions
on .Net CF). The problem occurs when I use reflection to get the value of a ConstantExpression
that represents a nullable constant.