C# 如何在CodeProperty中获取属性类型?T4
我包括了VisualStudioHelper。这里我通过属性获取所有类C# 如何在CodeProperty中获取属性类型?T4,c#,t4,C#,T4,我包括了VisualStudioHelper。这里我通过属性获取所有类 var classesWithMapAttribute = VisualStudioHelper.GetClassesByAttributeName("Map", projectName); 之后,我得到了类中的所有属性 foreach (CodeClass pi in classesWithMapAttribute) { var allProperties = VisualStudioHelper.Get
var classesWithMapAttribute = VisualStudioHelper.GetClassesByAttributeName("Map", projectName);
之后,我得到了类中的所有属性
foreach (CodeClass pi in classesWithMapAttribute)
{
var allProperties = VisualStudioHelper.GetAllCodeElementsOfType(pi.Members, vsCMElement.vsCMElementProperty, true);
}
那很好用。但是我需要得到属性的类型。如果我打电话
foreach(CodeProperty property in allPropertiesDto)
{
<#= property.Type #>
}
foreach(allPropertiesDto中的CodeProperty属性)
{
}
我将获得系统。结果是\u ComObject
你能告诉我,如何得到嵌套类型的属性吗 我很惭愧以前找不到答案
CodeTypeRef codeTypeRef = property.Type;
codeTypeRef.AsString // here we get type of property
您可以尝试以下方法:
类型t=property.PropertyType;//这将返回一个System.string欢迎使用StackOverflow,请尽量避免只回答代码,并尝试实际解释发生的情况,同时始终格式化您的codeproperty具有type codeproperty而没有定义PropertyType。这对我的处境是错误的。