Does anyone know how to unbox or convert a "1" as a nullable long?
-
...That pretty much says it all:
private void SetValue(object instance, PropertyInfo property, object data)
{
//some preliminary checks
if(property.PropertyType.IsAssignableFrom(data.GetType()))
property.SetValue(instance, data, null);
else
{
if(data is int)
{
int? unboxed = (int?)data;
property.SetValue(instance, unboxed, null);
}
else
property.SetValue(instance, Convert.ChangeType(data.ToString(), property.PropertyType), null);
}I have an object that has a property of type long? and the value "1" cannot be pushed into it. The failure is inside the "if(data is int)" branch. "Object of type 'System.Int32' cannot be converted to type 'System.Nullable '1[System.Int64]' How do I go about getting a System.Int32 into a System.Nullable [System.Int64] ??
"I need build Skynet. Plz send code"
-
...That pretty much says it all:
private void SetValue(object instance, PropertyInfo property, object data)
{
//some preliminary checks
if(property.PropertyType.IsAssignableFrom(data.GetType()))
property.SetValue(instance, data, null);
else
{
if(data is int)
{
int? unboxed = (int?)data;
property.SetValue(instance, unboxed, null);
}
else
property.SetValue(instance, Convert.ChangeType(data.ToString(), property.PropertyType), null);
}I have an object that has a property of type long? and the value "1" cannot be pushed into it. The failure is inside the "if(data is int)" branch. "Object of type 'System.Int32' cannot be converted to type 'System.Nullable '1[System.Int64]' How do I go about getting a System.Int32 into a System.Nullable [System.Int64] ??
"I need build Skynet. Plz send code"
-