I have the following code to iterate through some properties of my class

IEnumerable<CodeProperty> properties = CodeParser.GetEntityProjectItem(this, EntityClassType.Entity).FileCodeModel.GetClassesByName(method.EntityPropertyClassName).First().GetIEnumerable<CodeProperty>().Where(property => property.Getter != null && property.Access == vsCMAccess.vsCMAccessPublic);

This is all good, I get my properties, next I am build up a custom class with the name and types of the properties, this again is fine apart from arrays.

for a string Property I get the Name and "System.String"

for a string[] Property I get the Name and ""

How can I get the array type using CodeProperty

有帮助吗?

解决方案

I ended up using this extension method to get me working again

 public static string GetFullName(this CodeTypeRef codeType)
        {
            string fullName;

            if (codeType.TypeKind == vsCMTypeRef.vsCMTypeRefArray)
            {
                CodeTypeRef arrayType = codeType.ElementType;
                fullName = arrayType.AsFullName + "[]";
            }
            else
            {
                fullName = codeType.AsFullName;
            }
            return fullName;
        } 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top