Esempio n. 1
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;
        }