I’m attempting to map values of properties (via reflection) between different objects. This appears to be failing oddly on nullable value types. The following code:
destProperty.SetValue(destObject, sourceProperty.GetValue(sourceObject, null), null);
sets destProperty to null if destProperty is a nullable value type, despite sourceProperty having a value.
Surely this is a fairly common task – I must be missing something simple?
It was something simple – destProperty on this particular class seems to be written to ignore set calls unless certain other properties are set first. I’m pretty sure I wouldn’t have been responsible for such a flagrant violation of our coding standards, so I’m going to blame this one on the other guy. Pretty sure.
Thanks to Jimmy & tanascius for confirming it should work.