How to get property type in CodeProperty? T4

I have included VisualStudioHelper. Here I get all my classes by attribute

var classesWithMapAttribute = VisualStudioHelper.GetClassesByAttributeName("Map", projectName);

After that, I get all the properties in the class.

    foreach (CodeClass pi in classesWithMapAttribute)
{ 
   var allProperties = VisualStudioHelper.GetAllCodeElementsOfType(pi.Members, vsCMElement.vsCMElementProperty, true);
}

It works great. But I need to get property types. If i call

foreach(CodeProperty property in allPropertiesDto)
        {
             <#= property.Type #>
         }

I will get .__ ComObject System as a result

Could you tell me how to get a nested property type?

+4
source share
2 answers

I am ashamed that I could not find the answer before ...

CodeTypeRef codeTypeRef = property.Type;
codeTypeRef.AsString // here we get type of property
+1
source

You can try the following:

Type t = property .PropertyType; // This will return System.string

+2
source

Source: https://habr.com/ru/post/1583796/


All Articles