Search code examples
t4envdte

EnvDTE: How to find if a property is marked as virtual


I am putting together a template for creating buddy classes for classes generated by the Entity Framework -> Reverse Engineer Code First context menu item.

I really don't want to include the navigation properties that are marked as virtual. So how, using CodeProperty interface (or other EnvDTE code) discover if a property is marked as virtual?

To say it with pseudo code:

<# foreach (CodeElement ce in classInFile.Members)
        { 
            if (ce.Kind == vsCMElement.vsCMElementProperty && [ce not marked as virtual]) 
            {
                WriteDisplayName(ce); 
                WriteProperty(ce);
                WriteLine("");
            }
        } #>

Ie, how do I determine that ce is not marked as virtual?


Solution

  • Cast the CodeElement to a CodeProperty2 and check its OverrideKind property.