简体   繁体   English

确定生成的类型是否为值类型

[英]Determine if generated type is value-type

I have some types created via CodeDOM. 我有一些通过CodeDOM创建的类型。 Is there a way to determine if a type of a given property is a value-type? 有没有办法确定给定属性的类型是否为值类型?

For those declared within mscorlib it´s pretty easy as I can call Type.GetType and then check for Type.IsValueType . 对于在mscorlib中声明的那些,我很容易调用Type.GetType ,然后检查Type.IsValueType However for those types within my DOM we can´t use this approach as there´s no assembly to load the types from. 但是对于我的DOM中的那些类型,我们不能使用这种方法,因为没有程序集来加载类型。

var codeType = code.Types[0].Members[0];
bool isValueType = // get the runtime-type to determine if it is value-type or not

The CodeTypeDeclaration.IsStruct property, despite its name, does exactly this — determines whether the type is a value type. CodeTypeDeclaration.IsStruct属性,尽管它的名称,确实这样做 - 确定类型是否是值类型。 See the documentation here . 请参阅此处的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM