相关疑难解决方法(0)

有没有办法通过反射获得类型的别名?

我正在编写一个简单的代码生成应用程序来从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 c# reflection

19
推荐指数
3
解决办法
4748
查看次数

typeof(DateTime?).Name == Nullable`1

在.Net中使用Reflection typeof(DateTime?).Name返回"Nullable`1".

有没有办法将实际类型作为字符串返回.(在本例中为"DateTime"或"System.DateTime")

我明白的DateTime?Nullable<DateTime>.除此之外,我只是在寻找可空类型的类型.

.net c# system.reflection

7
推荐指数
3
解决办法
7212
查看次数

标签 统计

.net ×2

c# ×2

reflection ×1

system.reflection ×1