Example #1
0
        private MemberDeclarationSyntax createField(string fldName, TypeSyntax type, XP.ClassvarModifiersContext modifiers)
        {
            var list  = MakeSeparatedList(GenerateVariable(fldName, null));
            var decl  = _syntaxFactory.VariableDeclaration(type, list);
            var mods  = modifiers?.GetList <SyntaxToken>() ?? DefaultMethodModifiers(false, false, true);
            var fdecl = _syntaxFactory.FieldDeclaration(
                attributeLists: EmptyList <AttributeListSyntax>(),
                modifiers: mods,
                declaration: decl,
                semicolonToken: SyntaxFactory.MakeToken(SyntaxKind.SemicolonToken));

            return(fdecl);
        }
Example #2
0
        private MemberDeclarationSyntax createProperty(string fldName, TypeSyntax type, XSharpParserRuleContext context, XP.ClassvarModifiersContext modifiers)
        {
            var         accessors = _pool.Allocate <AccessorDeclarationSyntax>();
            BlockSyntax body      = null;

            if (_options.fox1)
            {
                var call = GenerateMethodCall(XSharpSpecialNames.GetProperty, MakeArgumentList(MakeArgument(GenerateLiteral(fldName))), true);
                body            = MakeBlock(GenerateReturn(call, true));
                body.XGenerated = true;
            }
            var accessor = _syntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration,
                                                              EmptyList <AttributeListSyntax>(), EmptyList(),
                                                              SyntaxFactory.MakeToken(SyntaxKind.GetKeyword),
                                                              body,
                                                              null,
                                                              SyntaxFactory.MakeToken(SyntaxKind.SemicolonToken));

            accessor.XNode      = context;
            accessor.XGenerated = true;
            accessors.Add(accessor);
            if (_options.fox1)
            {
                var call = GenerateMethodCall(XSharpSpecialNames.SetProperty, MakeArgumentList(MakeArgument(GenerateLiteral(fldName)), MakeArgument(GenerateSimpleName("value"))), true);
                body            = MakeBlock(GenerateExpressionStatement(call, true));
                body.XGenerated = true;
            }
            accessor = _syntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration,
                                                          EmptyList <AttributeListSyntax>(), EmptyList(),
                                                          SyntaxFactory.MakeToken(SyntaxKind.SetKeyword),
                                                          body,
                                                          null,
                                                          SyntaxFactory.MakeToken(SyntaxKind.SemicolonToken));
            accessor.XNode      = context;
            accessor.XGenerated = true;
            accessors.Add(accessor);
            var id           = SyntaxFactory.MakeIdentifier(fldName);
            var accessorList = _syntaxFactory.AccessorList(SyntaxFactory.MakeToken(SyntaxKind.OpenBraceToken),
                                                           accessors, SyntaxFactory.MakeToken(SyntaxKind.CloseBraceToken));

            _pool.Free(accessors);
            var mods = modifiers?.GetList <SyntaxToken>() ?? DefaultMethodModifiers(false, false, false);
            var prop = _syntaxFactory.PropertyDeclaration(
                attributeLists: EmptyList <AttributeListSyntax>(),
                modifiers: mods,
                type: type,
                explicitInterfaceSpecifier: null,
                identifier: id,
                accessorList: accessorList,
                expressionBody: null,
                initializer: null,
                semicolonToken: SyntaxFactory.MakeToken(SyntaxKind.SemicolonToken));

            return(prop);
        }