Пример #1
0
        private static void ProvideWriteMethod1(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberField endsWithNewline, CodeMemberProperty GenerationEnvironment, CodeVariableReferenceExpression textToAppend)
        {
            CodeExpression   codeExpression   = typeof(Environment).Expr().Prop("NewLine");
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(null, "Write", "Write text directly into the generated output", (MemberAttributes)24578, new CodeConditionStatement(CodeDomHelpers.Call(typeof(string), "IsNullOrEmpty", textToAppend), new CodeMethodReturnStatement()), new CodeCommentStatement("If we're starting off, or if the previous text ended with a newline,"), new CodeCommentStatement("we have to append the current indent first."), new CodeConditionStatement(new CodeBinaryOperatorExpression(GenerationEnvironment.Ref().Prop("Length").VEquals(0.Prim()), CodeBinaryOperatorType.BooleanOr, endsWithNewline.Ref()), GenerationEnvironment.Ref().CallS("Append", currentIndent.Ref()), endsWithNewline.Ref().Assign(false.Prim())), new CodeCommentStatement("Check if the current text ends with a newline"), new CodeConditionStatement(textToAppend.Call("EndsWith", codeExpression, typeof(StringComparison).Expr().Prop("CurrentCulture")), new CodeAssignStatement(endsWithNewline.Ref(), true.Prim())), new CodeCommentStatement("This is an optimization. If the current indent is \"\", then we don't have to do any"), new CodeCommentStatement("of the more complex stuff further down."), new CodeConditionStatement(currentIndent.Ref().Prop("Length").VEquals(0.Prim()), GenerationEnvironment.Ref().CallS("Append", textToAppend), new CodeMethodReturnStatement()), new CodeCommentStatement("Everywhere there is a newline in the text, add an indent after it"), textToAppend.Assign(textToAppend.Call("Replace", codeExpression, codeExpression.Add(currentIndent.Ref()))), new CodeCommentStatement("If the text ends with a newline, then we should strip off the indent added at the very end"), new CodeCommentStatement("because the appropriate indent will be added when the next time Write() is called"), new CodeConditionStatement(endsWithNewline.Ref(), new CodeStatement[1]
            {
                GenerationEnvironment.Ref().CallS("Append", textToAppend, 0.Prim(), textToAppend.Prop("Length").Subtract(currentIndent.Ref().Prop("Length")))
            }, new CodeStatement[1]
            {
                GenerationEnvironment.Ref().CallS("Append", textToAppend)
            }));

            codeMemberMethod.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Transform-time helpers"));
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), textToAppend.VariableName));
            members.Add(codeMemberMethod);
        }
Пример #2
0
        private static void ProvideErrorMethod(CodeTypeMemberCollection members, CodeMemberProperty Errors, CodeVariableReferenceExpression error)
        {
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(null, "Error", "Raise an error", (MemberAttributes)24578, new CodeVariableDeclarationStatement(typeof(CompilerError), "error", typeof(CompilerError).New()), error.Prop("ErrorText").Assign(new CodeVariableReferenceExpression("message")), Errors.Ref().CallS("Add", error));

            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "message"));
            members.Add(codeMemberMethod);
        }
Пример #3
0
        private static void ProvideWriteLineMethod1(CodeTypeMemberCollection members, CodeMemberField endsWithNewline, CodeMemberProperty GenerationEnvironment, CodeVariableReferenceExpression textToAppend)
        {
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(null, "WriteLine", "Write text directly into the generated output", (MemberAttributes)24578, CodeDomHelpers.Call("Write", textToAppend), GenerationEnvironment.Ref().CallS("AppendLine"), endsWithNewline.Ref().Assign(true.Prim()));

            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), textToAppend.VariableName));
            members.Add(codeMemberMethod);
        }
Пример #4
0
        private static void ProvidePopIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression codeVariableReferenceExpression  = new CodeVariableReferenceExpression("indentLength");
            CodeVariableReferenceExpression codeVariableReferenceExpression2 = new CodeVariableReferenceExpression("returnValue");
            CodeMemberMethod value = CodeDomHelpers.CreateMethod(typeof(string), "PopIndent", "Remove the last indent that was added with PushIndent", (MemberAttributes)24578, new CodeVariableDeclarationStatement(typeof(string), codeVariableReferenceExpression2.VariableName, string.Empty.Prim()), new CodeConditionStatement(indentLengths.Ref().Prop("Count").Gt(0.Prim()), new CodeVariableDeclarationStatement(typeof(int), codeVariableReferenceExpression.VariableName, indentLengths.Ref().Index(indentLengths.Ref().Prop("Count").Subtract(1.Prim()))), indentLengths.Ref().CallS("RemoveAt", indentLengths.Ref().Prop("Count").Subtract(1.Prim())), new CodeConditionStatement(codeVariableReferenceExpression.Gt(0.Prim()), codeVariableReferenceExpression2.Assign(currentIndent.Ref().Call("Substring", currentIndent.Ref().Prop("Length").Subtract(codeVariableReferenceExpression))), currentIndent.Ref().Assign(currentIndent.Ref().Call("Remove", currentIndent.Ref().Prop("Length").Subtract(codeVariableReferenceExpression))))), new CodeMethodReturnStatement(codeVariableReferenceExpression2));

            members.Add(value);
        }
Пример #5
0
        private static void ProvidePushIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression codeVariableReferenceExpression = new CodeVariableReferenceExpression("indent");
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(null, "PushIndent", "Increase the indent", (MemberAttributes)24578, new CodeConditionStatement(codeVariableReferenceExpression.VEquals(CodeDomHelpers.nullEx), new CodeThrowExceptionStatement(typeof(ArgumentNullException).New("indent".Prim()))), currentIndent.Ref().Assign(currentIndent.Ref().Add(codeVariableReferenceExpression)), indentLengths.Ref().CallS("Add", codeVariableReferenceExpression.Prop("Length")));

            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "indent"));
            members.Add(codeMemberMethod);
        }
Пример #6
0
        private static void ProvideClearIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeMemberMethod codeMemberMethod = CodeDomHelpers.CreateMethod(null, "ClearIndent", "Remove any indentation", (MemberAttributes)24578, indentLengths.Ref().CallS("Clear"), currentIndent.Ref().Assign(string.Empty.Prim()));

            codeMemberMethod.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, "Transform-time helpers"));
            members.Add(codeMemberMethod);
        }
Пример #7
0
        private static void ProvideWarningMethod(CodeTypeMemberCollection members, CodeMemberProperty Errors, CodeVariableReferenceExpression error)
        {
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(null, "Warning", "Raise a warning", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { new CodeVariableDeclarationStatement(typeof(CompilerError), "error", typeof(CompilerError).New()), error.Prop("ErrorText").Assign(new CodeVariableReferenceExpression("message")), error.Prop("IsWarning").Assign(true.Prim()), Errors.Ref().CallS("Add", new CodeExpression[] { error }) });

            method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "message"));
            members.Add(method);
        }
Пример #8
0
        private static void ProvidePushIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression lhs = new CodeVariableReferenceExpression("indent");
            CodeMemberMethod method             = CodeDomHelpers.CreateMethod(null, "PushIndent", "Increase the indent", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { new CodeConditionStatement(lhs.VEquals(CodeDomHelpers.nullEx), new CodeStatement[] { new CodeThrowExceptionStatement(typeof(ArgumentNullException).New(new CodeExpression[] { "indent".Prim() })) }), currentIndent.Ref().Assign(currentIndent.Ref().Add(lhs)), indentLengths.Ref().CallS("Add", new CodeExpression[] { lhs.Prop("Length") }) });

            method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "indent"));
            members.Add(method);
        }
Пример #9
0
        private static void ProvidePopIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeVariableReferenceExpression lhs         = new CodeVariableReferenceExpression("indentLength");
            CodeVariableReferenceExpression expression2 = new CodeVariableReferenceExpression("returnValue");
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(typeof(string), "PopIndent", "Remove the last indent that was added with PushIndent", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { new CodeVariableDeclarationStatement(typeof(string), expression2.VariableName, string.Empty.Prim()), new CodeConditionStatement(indentLengths.Ref().Prop("Count").Gt(0.Prim()), new CodeStatement[] { new CodeVariableDeclarationStatement(typeof(int), lhs.VariableName, indentLengths.Ref().Index(new CodeExpression[] { indentLengths.Ref().Prop("Count").Subtract(1.Prim()) })), indentLengths.Ref().CallS("RemoveAt", new CodeExpression[] { indentLengths.Ref().Prop("Count").Subtract(1.Prim()) }), new CodeConditionStatement(lhs.Gt(0.Prim()), new CodeStatement[] { expression2.Assign(currentIndent.Ref().Call("Substring", new CodeExpression[] { currentIndent.Ref().Prop("Length").Subtract(lhs) })), currentIndent.Ref().Assign(currentIndent.Ref().Call("Remove", new CodeExpression[] { currentIndent.Ref().Prop("Length").Subtract(lhs) })) }) }), new CodeMethodReturnStatement(expression2) });

            members.Add(method);
        }
Пример #10
0
        private static void ProvideClearIndentMethod(CodeTypeMemberCollection members, CodeMemberField currentIndent, CodeMemberProperty indentLengths)
        {
            CodeMemberMethod method = CodeDomHelpers.CreateMethod(null, "ClearIndent", "Remove any indentation", MemberAttributes.Public | MemberAttributes.Final, new CodeObject[] { indentLengths.Ref().CallS("Clear", new CodeExpression[0]), currentIndent.Ref().Assign(string.Empty.Prim()) });

            method.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, "Transform-time helpers"));
            members.Add(method);
        }