c# Reflection return "Nullable`1"
c#, c#-3.0, c#-4.0
Solution
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;
Problem
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" ```