反射获取可空属性的数据类型

 

//获取T类型的属性类型和值
PropertyInfo[] pis = entity.GetType().GetProperties();

//如果当前列为可空类型,则获取其基类数据类型
//如果不获取基类类型的话,则当前列的数据类型为
if(typeColumn.IsGenericType && typeColumn.GetGenericTypeDefinition() == typeof(Nullable<>))
{
typeName = typeColumn.GetGenericArguments()[0].Name;
}
else
{
typeName = typeColumn.Name;
}

原文地址:https://www.cnblogs.com/chensong0524/p/13521626.html