getting basic data types using reflection than nullable
While using class properties to use for data base connectivity, i.e. LINQ TO SQL, I was facing issue for nullable types.
I was using Reflection to fetch property type names, but for NULLABLE properties it use to send me property type name as NULLABLE`1.
I was suppose to use following switch case (Determine Nullable properties via reflection)
public static string getJSType(PropertyInfo propertyinfo)
{
//GetCoreType function returns Property type.
switch (GetCoreType(propertyinfo.PropertyType).Name.ToUpper())
{
case "INT16":
return "number";
case "UINT16":
return "number";
case "SHORT":
return "number";
case "USHORT":
return "number";
case "INT32":
return "number";
case "UINT32":
return "number";
case "INT":
return "number";
case "UINT":
return "number";
case "INT64":
return "longnumber";
case "UINT64":
return "longnumber";
case "LONG":
return "longnumber";
case "ULONG":
return "longnumber";
case "DECIMAL":
return "decimal";
case "DOUBLE":
return "float";
case "BIGINT":
return "longnumber";
case "STRING":
return "text";
case "DATETIME":
return "datepicker";
case "BOOLEAN":
return "flag";
}
//}
return "text";
}
To determine type of NULLABLE properties via reflection, I used following function GetCoreType
private Type GetCoreType(Type type)
{
if (type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(Nullable<>))
return Nullable.GetUnderlyingType(type);
else
return type;
}
Find Type of Nullable Properties via Reflection.
Determine type of Nullable properties view Relection.
While using reflection get core property type of nullable properties.
0 comments:
Post a Comment