Пример #1
0
        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return;
            }

            ExpressionRenderingMode oldMode = context.GetExpressionRenderingMode();

            var sb = new StringBuilder();

            sb.Append(", Tuple.Create<string,object,bool> (");
            sb.WriteCStyleStringLiteral(Prefix.Value);
            sb.Append(", ");

            if (ValueGenerator != null)
            {
                context.SetExpressionRenderingMode(ExpressionRenderingMode.InjectCode);
            }
            else
            {
                sb.WriteCStyleStringLiteral(Value);
                sb.Append(", true)");
            }
            context.BufferStatementFragment(sb.ToString());

            if (ValueGenerator != null)
            {
                ValueGenerator.Value.GenerateCode(target, context);
                context.FlushBufferedStatement();
                context.SetExpressionRenderingMode(oldMode);
                context.AddStatement(", false)");
            }
            else
            {
                context.FlushBufferedStatement();
            }
        }
Пример #2
0
        public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return;
            }

            var sb = new StringBuilder();

            if (isExpression)
            {
                sb.Append(", false)");
                context.SetExpressionRenderingMode(oldRenderingMode);
            }
            else
            {
                sb.Append("}), false)");
            }

            context.AddStatement(sb.ToString());
            context.TargetWriterName = oldTargetWriter;
        }
Пример #3
0
        public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return;
            }

            Block child = target.Children.Where(n => n.IsBlock).Cast <Block> ().FirstOrDefault();

            isExpression = child != null && child.Type == BlockType.Expression;

            var sb = new StringBuilder();

            sb.Append(", Tuple.Create<string,object,bool> (");
            sb.WriteCStyleStringLiteral(Prefix.Value);
            sb.Append(", ");

            if (isExpression)
            {
                oldRenderingMode = context.GetExpressionRenderingMode();
                context.SetExpressionRenderingMode(ExpressionRenderingMode.InjectCode);
            }
            else
            {
                sb.AppendFormat(
                    "new {0} ({1} => {{",
                    context.Host.GeneratedClassContext.TemplateTypeName,
                    ValueWriterName);
            }

            context.MarkEndOfGeneratedCode();
            context.BufferStatementFragment(sb.ToString());

            oldTargetWriter          = context.TargetWriterName;
            context.TargetWriterName = ValueWriterName;
        }