我正在使用较旧的 Oracle 数据库,并且我觉得可能有更好的方法来取消我从数据库中检索的值的装箱。
目前,我有一个充满不同类型特定方法的静态类:
public static int? Int(object o)
{
try
{
return (int?)Convert.ToInt32(o);
}
catch (Exception)
{
return null;
}
}
..等等不同类型,但我觉得应该有更好的方法?如果我想拆箱一个值,我会做一些事情......
int i;
i = nvl.Int(dataRow["column"]); //In this instance, "column" is of a numeric database type
我考虑过使用泛型类来处理所有不同的类型,但我真的想不出最好的方法。
有任何想法吗?