/// <summary>
        /// Generates .NET code for an enumeration.
        /// </summary>
        /// <param name="context">Enumeration AST.</param>
        /// <returns></returns>
        public override CodeGeneratorBase VisitEnumerationStmt(VisualBasic6Parser.EnumerationStmtContext context)
        {
            SyntaxTokenList accessibility = new SyntaxTokenList();

            VisualBasic6Parser.PublicPrivateVisibilityContext vis = context.publicPrivateVisibility();

            if (vis != null)
            {
                if (vis.PUBLIC() != null)
                {
                    accessibility = RoslynUtils.PublicModifier;
                }
                else if (vis.PRIVATE() != null)
                {
                    accessibility = RoslynUtils.PrivateModifier;
                }
            }

            EnumStatementSyntax stmt      = SyntaxFactory.EnumStatement(context.ambiguousIdentifier().GetText()).WithModifiers(accessibility);
            EnumBlockSyntax     enumBlock = SyntaxFactory.EnumBlock(stmt);
            List <EnumMemberDeclarationSyntax> members = new List <EnumMemberDeclarationSyntax>();

            foreach (var constant in context.enumerationStmt_Constant())
            {
                string constantName = constant.ambiguousIdentifier().GetText();

                if (constant.valueStmt() != null)
                {
                    string constantValue = constant.valueStmt().GetText();

                    members.Add(SyntaxFactory.EnumMemberDeclaration(constantName)
                                .WithInitializer(SyntaxFactory.EqualsValue(SyntaxFactory.NumericLiteralExpression(SyntaxFactory.ParseToken(constantValue)))));
                }
                else
                {
                    members.Add(SyntaxFactory.EnumMemberDeclaration(constantName));
                }
            }

            mMainDeclMembers.Add(enumBlock.WithMembers(SyntaxFactory.List <StatementSyntax>(members)));
            return(this);
        }
Beispiel #2
0
 public override void VisitEnumStatement(EnumStatementSyntax node)
 {
 }
 public override void VisitEnumStatement(EnumStatementSyntax node) =>
 TryAddPublicApi(node);