I'm working with reflection and I need a business validation, so I created a class declared in the following way:
public class NullChecker<T>
There I created a method that run that validation:
public static T ReturnValue2(T serviceValue, T dbValue, Type propType)
{
T result;
object svcValueConverted = serviceValue;
object defaultValue = null;
if (propType.IsPrimitive)
{
svcValueConverted = GetConvertedValue(serviceValue);
defaultValue = GetDefaultValue(propType);
var x = svcValueConverted.GetType();
var y = defaultValue.GetType();
}
if (svcValueConverted == defaultValue)
{
result = dbValue;
}
return result;
}
I'm getting this issue when a Int.32 object type comes, even that the converted value (0), and the default value (0) are the same, the if statement is not working and jump to the next line (i.e. 0 == 0). I don't really know which is the problem here, if anyone has experimented this, It would be nice to get some ideas.
Thank u in advance, happy code.
Aucun commentaire:
Enregistrer un commentaire