我正在编写一个简单的代码生成应用程序来从DB2数据库模式构建POCO.我知道这没关系,但我更喜欢使用类型别名而不是实际的系统类型名称(如果它们可用),即"int"而不是"Int32".有没有办法使用反射,我可以得到一个类型的别名,而不是它的实际类型?
//Get the type name
var typeName = column.DataType.Name;
//If column.DataType is, say, Int64, I would like the resulting property generated
//in the POCO to be...
public long LongColumn { get; set; }
//rather than what I get now using the System.Reflection.MemberInfo.Name property:
public Int64 LongColumn { get; set; }
Run Code Online (Sandbox Code Playgroud)
提前致谢.
在.Net中使用Reflection typeof(DateTime?).Name返回"Nullable`1".
有没有办法将实际类型作为字符串返回.(在本例中为"DateTime"或"System.DateTime")
我明白的DateTime?是Nullable<DateTime>.除此之外,我只是在寻找可空类型的类型.