コード例 #1
0
        public void AppendNewLine()
        {
            var writeInvoke = CodeDomFluentBuilder
                              .GetCodeMethodInvokeExpression("WriteLine", TextWriterVariableName)
                              .WithInvokePrimitiveParameter("");

            RenderMethod.AddExpressionStatement(writeInvoke);
        }
コード例 #2
0
        public void AppendCodeToString(string code)
        {
            var writeInvoke = CodeDomFluentBuilder
                              .GetCodeMethodInvokeExpression("Write", TextWriterVariableName)
                              .WithInvokeCodeSnippetToStringParameter(code);

            RenderMethod.AddExpressionStatement(writeInvoke);
        }
コード例 #3
0
        public void AppendSelfClosingTagSuffix()
        {
            var renderValueOrKeyAsString = CodeDomFluentBuilder
                                           .GetCodeMethodInvokeExpression("base.AppendSelfClosingTagSuffix");

            var writeInvoke = CodeDomFluentBuilder
                              .GetCodeMethodInvokeExpression("Write", TextWriterVariableName)
                              .WithInvokeCodeParameter(renderValueOrKeyAsString);

            RenderMethod.AddExpressionStatement(writeInvoke);
        }
コード例 #4
0
        public void AppendVariable(string variableName)
        {
            var renderValueOrKeyAsString = CodeDomFluentBuilder
                                           .GetCodeMethodInvokeExpression("RenderValueOrKeyAsString")
                                           .WithInvokePrimitiveParameter(variableName);

            var writeInvoke = CodeDomFluentBuilder
                              .GetCodeMethodInvokeExpression("Write", TextWriterVariableName)
                              .WithInvokeCodeParameter(renderValueOrKeyAsString);

            RenderMethod.AddExpressionStatement(writeInvoke);
        }
コード例 #5
0
        public void AppendDocType(string docTypeId)
        {
            var docType = CodeDomFluentBuilder
                          .GetCodeMethodInvokeExpression("GetDocType")
                          .WithInvokePrimitiveParameter(docTypeId);

            var writeInvoke = CodeDomFluentBuilder
                              .GetCodeMethodInvokeExpression("Write", TextWriterVariableName)
                              .WithInvokeCodeParameter(docType);

            RenderMethod.AddExpressionStatement(writeInvoke);
        }
コード例 #6
0
        private void AppenAttributeWithValue(string name, IEnumerable <HamlNode> valueFragments, char quoteToUse)
        {
            string variableName = "value_" + RenderMethod.Statements.Count;

            RenderMethod.AddStatement(
                CodeDomFluentBuilder.GetDeclaration(typeof(StringBuilder), variableName,
                                                    new CodeObjectCreateExpression("System.Text.StringBuilder",
                                                                                   new CodeExpression[] {})));

            foreach (var fragment in valueFragments)
            {
                CodeExpression parameter;
                if (fragment is HamlNodeTextVariable)
                {
                    string nodeVariableName = ((HamlNodeTextVariable)fragment).VariableName;
                    if (nodeVariableName.All(ch => Char.IsLetterOrDigit(ch)))
                    {
                        parameter = CodeDomFluentBuilder.GetCodeMethodInvokeExpression(
                            "base.RenderValueOrKeyAsString")
                                    .WithInvokePrimitiveParameter(nodeVariableName);
                    }
                    else
                    {
                        parameter = CodeDomFluentBuilder.GetCodeMethodInvokeExpression("ToString", "Convert")
                                    .WithCodeSnippetParameter(nodeVariableName);
                    }
                }
                else
                {
                    parameter = new CodePrimitiveExpression {
                        Value = fragment.Content
                    };
                }

                RenderMethod.AddExpressionStatement(
                    CodeDomFluentBuilder.GetCodeMethodInvokeExpression("Append", variableName)
                    .WithParameter(parameter));
            }

            var outputExpression = CodeDomFluentBuilder
                                   .GetCodeMethodInvokeExpression("base.RenderAttributeNameValuePair")
                                   .WithInvokePrimitiveParameter(name)
                                   .WithParameter(CodeDomFluentBuilder.GetCodeMethodInvokeExpression("ToString", variableName))
                                   .WithInvokePrimitiveParameter(quoteToUse);

            RenderMethod.AddExpressionStatement(
                CodeDomFluentBuilder.GetCodeMethodInvokeExpression("Write", TextWriterVariableName)
                .WithParameter(outputExpression));
        }
コード例 #7
0
 private void AppendAttributeWithoutValue(string name)
 {
     RenderMethod.AddExpressionStatement(
         CodeDomFluentBuilder.GetCodeMethodInvokeExpression("Write", TextWriterVariableName)
         .WithInvokePrimitiveParameter(" " + name));
 }