public void Visit(TableColumnArg arg)
        {
            var field = new CodeMemberField();
            field.Name = arg.Variable;
            field.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            field.Type = new CodeTypeReference(TablePrimitive.FromString(arg.Type).Type);

            _codeStack.Peek().ParentMemberDefinitions.Add(field);
        }
Пример #2
0
        private void BuildIRowReaderImplementation(CodeTypeDeclaration type, TableColumnArg[] tableArgs)
        {
            var method = new CodeMemberMethod();
            method.Name = "Load";
            method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string[]), "columns"));

            for (int x = 0; x < tableArgs.Length; x++)
            {
                var varType = TablePrimitive.FromString(tableArgs[x].Type);
                var left = new CodeFieldReferenceExpression(null, tableArgs[x].Variable);
                CodeExpression right = new CodeIndexerExpression(new CodeTypeReferenceExpression("columns"), new CodeSnippetExpression(x.ToString()));
                right = varType.ToNative(right);

                method.Statements.Add(new CodeAssignStatement(left, right));
            }

            type.Members.Add(method);
        }
Пример #3
0
        private void BuildIRowWriterImplementation(CodeTypeDeclaration type, TableColumnArg[] tableArgs)
        {
            var method = new CodeMemberMethod();
            method.Name = "Line";
            method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            method.ReturnType = new CodeTypeReference(typeof(string[]));

            var arrayDecl = new CodeVariableDeclarationStatement(typeof(string[]), "print", new CodeArrayCreateExpression(typeof(string[]), tableArgs.Length));
            method.Statements.Add(arrayDecl);
            for (int x = 0; x < tableArgs.Length; x++)
            {
                var left = new CodeIndexerExpression(new CodeTypeReferenceExpression("print"), new CodeSnippetExpression(x.ToString()));
                var right = new CodeMethodInvokeExpression(
                     new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(string)), "Format"),
                         new CodeSnippetExpression("\"{0}\""), new CodeVariableReferenceExpression(tableArgs[x].Variable));

                method.Statements.Add(new CodeAssignStatement(left, right));
            }

            method.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("print")));
            type.Members.Add(method);
        }