I define my class, my fields pog_02integer and pog_03smallint are integer that can have null value (int?)
public class v_cCfgDeclaraciones {
public string pog_idcotizacion {get;set;}
public string pog_01varchar {get;set;}
public int? pog_02integer {get;set;}
public int? pog_03smallint {get;set;}
public DateTime? pog_04date {get;set;}
}
How I can return "integer" and not System.DBNull? I try this, but I can't find a way to return "integer" I just returned System.DBNull if I remove "?" in the name of the field as a whole recognizes but can't assign a null value. I would like to help me resolve this problem, where I can define the field with "?" and I recognize the integer data type and not System.DBNull
foreach (System.Data.DataRow dr in dt.Rows){
object o = Activator.CreateInstance(iSingleType);
foreach (System.Reflection.PropertyInfo Registro in proRegistro){
if ((Registro.PropertyType.Namespace != "System.Collections.Generic") && (AtributoLectura(Registro.GetCustomAttributes(true)))){
TipoDato = Registro.PropertyType.Name;
if (TipoDato == "Nullable`1") {
string v = dr[Registro.Name.ToUpper()].GetType().FullName;
int i = v.IndexOf('.');
int l = v.Length - i;
TipoDato = v.Substring(i, l);
}
switch (TipoDato){
case "Char":
case "String":
break;
case "int": case "integer"
There is a helper method to get a nullable type's underlying value type: Nullable.GetUnderlyingType
. It will return null if the given type is not a closed over nullable type. I would do something like this:
Type type = Nullable.GetUnderlyingType(Registro.PropertyType) ?? Registro.PropertyType;
string typeName = type.Name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With