/// <summary>
        /// Create the code for the Initialize method after its call to base.Initialize
        /// </summary>
        private void GeneratePostInitCode(string nameValue, string typeValue, CodeMemberField field)
        {
            CodeStatementCollection          codeStatementCollection          = new CodeStatementCollection();
            CodeVariableDeclarationStatement codeVariableDeclarationStatement = new CodeVariableDeclarationStatement(typeof(bool).Ref(), nameValue + "ValueAcquired", false.Prim());
            CodeVariableReferenceExpression  codeVariableReferenceExpression  = codeVariableDeclarationStatement.Ref();
            CodeTypeReference typeReference    = new CodeTypeReference(typeValue, CodeTypeReferenceOptions.GlobalReference);
            CodeStatement     setValueAcquired = codeVariableReferenceExpression.Assign(true.Prim());

            codeStatementCollection.Add(codeVariableDeclarationStatement);
            GenerateSessionLookup(nameValue, field, codeStatementCollection, setValueAcquired, typeReference);
            if (hostSpecific)
            {
                GenerateHostResolveParameterValueLookup(nameValue, field, codeStatementCollection, codeVariableReferenceExpression, typeReference, setValueAcquired, typeValue);
            }
            GenerateCallContextLookup(nameValue, field, codeStatementCollection, codeVariableReferenceExpression, typeReference, typeValue);
            CodeGeneratorOptions standardOptions = StandardOptions;

            using (StringWriter writer = new StringWriter(postInitializationBuffer, CultureInfo.InvariantCulture))
            {
                foreach (CodeStatement item in codeStatementCollection)
                {
                    languageCodeDomProvider.GenerateCodeFromStatement(item, writer, standardOptions);
                }
            }
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
        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);
        }