コード例 #1
0
        public static ClassDeclarationSyntax GeneratePackageGuidsClass(XDocument vsctDocument)
        {
            VisualStudioWorkspace  componentModelService = Services.GetComponentModelService <VisualStudioWorkspace>();
            ClassDeclarationSyntax declarationSyntax     = SyntaxFactory.ClassDeclaration("GuidSymbols").WithModifiers(Modifiers.InternalStaticPartial);
            XElement xelement = vsctDocument.Root.Element(XNames.Symbols);
            SyntaxList <FieldDeclarationSyntax> syntaxList = SyntaxFactory.List <FieldDeclarationSyntax>();

            foreach (XElement element in xelement.Elements(XNames.GuidSymbol))
            {
                string str  = element.Attribute("name").Value;
                string guid = element.Attribute("value").Value.TrimStart('{').TrimEnd('}');
                declarationSyntax = declarationSyntax.AddMembers(new MemberDeclarationSyntax[1]
                {
                    FieldGenerator.GenerateStaticGuidField(str)
                });
                syntaxList = @syntaxList.Add(FieldGenerator.GenerateConstantGuidStringField(str, guid));
            }
            SyntaxList <FieldDeclarationSyntax> .Enumerator enumerator = @syntaxList.GetEnumerator();
            while (@enumerator.MoveNext())
            {
                FieldDeclarationSyntax current = @enumerator.Current;
                declarationSyntax = declarationSyntax.AddMembers(new MemberDeclarationSyntax[1]
                {
                    current
                });
            }
            return((ClassDeclarationSyntax)Formatter.Format(declarationSyntax, componentModelService, null, new CancellationToken()));
        }
コード例 #2
0
        public static ClassDeclarationSyntax GeneratePackageIdsClass(XDocument vsctDocument)
        {
            VisualStudioWorkspace  componentModelService = Services.GetComponentModelService <VisualStudioWorkspace>();
            ClassDeclarationSyntax declarationSyntax     = SyntaxFactory.ClassDeclaration("IDSymbols").WithModifiers(Modifiers.InternalStaticPartial);

            foreach (XContainer element1 in vsctDocument.Root.Element(XNames.Symbols).Elements(XNames.GuidSymbol))
            {
                foreach (XElement element2 in element1.Elements(XNames.IDSymbol))
                {
                    string name  = element2.Attribute("name").Value;
                    int    int32 = Convert.ToInt32(element2.Attribute("value").Value, 16);
                    declarationSyntax = declarationSyntax.AddMembers(new MemberDeclarationSyntax[1]
                    {
                        FieldGenerator.GenerateConstantIntField(name, int32)
                    });
                }
            }
            return((ClassDeclarationSyntax)Formatter.Format(declarationSyntax, componentModelService, null, new CancellationToken()));
        }
コード例 #3
0
        public static ClassDeclarationSyntax GenerateCommandIdsClass(XDocument vsctDocument)
        {
            SyntaxList <MemberDeclarationSyntax> syntaxList = SyntaxFactory.List <MemberDeclarationSyntax>();
            XElement xelement = vsctDocument.Root.Element(XNames.Commands).Element(XNames.Buttons);

            if (xelement != null && xelement.HasElements)
            {
                foreach (XElement element in xelement.Elements(XNames.Button))
                {
                    string str = element.AttributeValueNull("id");
                    NameMaker.MakeCommandIDName(str);
                    string nameForButtonName = VsctHelper.GetGuidSymbolNameForButtonName(vsctDocument, str);
                    syntaxList = @syntaxList.Add(FieldGenerator.GenerateCommandIDField(str, nameForButtonName));
                }
            }
            return(SyntaxFactory.ClassDeclaration("CommandIds")
                   .WithModifiers(Modifiers.InternalStaticPartial)
                   .WithMembers(syntaxList)
                   .NormalizeWhitespace());
        }