This project has moved and is read-only. For the latest updates, please go here.

Setter Nullable types



Not sure if this is really an issue ...
But want to inform SetPropertyValue is not working on Nullable types when the setter has a 'value' assignment.

public int? Test{ get; set; } // works
public int? Test{ get{ return _a; } set{ _a = value; } // Throw InvalidCastOperation.



coradinibr wrote Jun 5, 2012 at 10:12 PM

The issue is not at the library, but may confuse us ..

The issue is caused by the way .NET handle casting.
So if the value you receive is boxed from object to an int (and sometimes you don't have a way to control this) and your property is of type long (int64), .NET won't do the conversion ...

To reproduce once case..
  • Create a class, create a property of type long.
  • Instantiate your object, call obj.SetPropertyValue("prop", 1);
    1 will be converted to int32 but your property is int64, so ... you got the idea.
Many thanks!

mertner wrote Sep 14, 2012 at 5:09 AM

Sorry for not commenting on this any sooner.

That behavior is actually a bit unfortunate. We may lack a cast in the generated IL for this particular scenario, but I'd have to investigate the exact cause of the problem to know more about it.

No promises on a timeline for a fix, but at least it's on my radar now ;)