如何在 CodeProperty 中获取 属性 的类型? T4
How get type of property in CodeProperty ? T4
我包括了 VisualStudioHelper。在这里,我通过 Attribute
获得了我所有的 类
var classesWithMapAttribute = VisualStudioHelper.GetClassesByAttributeName("Map", projectName);
之后,我获得了 Class 中的所有属性。
foreach (CodeClass pi in classesWithMapAttribute)
{
var allProperties = VisualStudioHelper.GetAllCodeElementsOfType(pi.Members, vsCMElement.vsCMElementProperty, true);
}
效果很好。但我需要获取属性类型。如果我打电话给
foreach(CodeProperty property in allPropertiesDto)
{
<#= property.Type #>
}
我会得到 System.__ComObject 作为结果
你能告诉我,如何获得 属性 的嵌套类型吗?
很惭愧以前找不到答案...
CodeTypeRef codeTypeRef = property.Type;
codeTypeRef.AsString // here we get type of property
你可以试试这个:
键入 t = property.PropertyType; // 这将 return 一个 System.string
我包括了 VisualStudioHelper。在这里,我通过 Attribute
获得了我所有的 类var classesWithMapAttribute = VisualStudioHelper.GetClassesByAttributeName("Map", projectName);
之后,我获得了 Class 中的所有属性。
foreach (CodeClass pi in classesWithMapAttribute)
{
var allProperties = VisualStudioHelper.GetAllCodeElementsOfType(pi.Members, vsCMElement.vsCMElementProperty, true);
}
效果很好。但我需要获取属性类型。如果我打电话给
foreach(CodeProperty property in allPropertiesDto)
{
<#= property.Type #>
}
我会得到 System.__ComObject 作为结果
你能告诉我,如何获得 属性 的嵌套类型吗?
很惭愧以前找不到答案...
CodeTypeRef codeTypeRef = property.Type;
codeTypeRef.AsString // here we get type of property
你可以试试这个:
键入 t = property.PropertyType; // 这将 return 一个 System.string