public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context) { if (context.Host.EnableInstrumentation && context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput) { Span contentSpan = target.Children .OfType<Span>() .Where(s => s.Kind == SpanKind.Code || s.Kind == SpanKind.Markup) .FirstOrDefault(); if (contentSpan != null) { context.AddContextCall(contentSpan, context.Host.GeneratedClassContext.BeginContextMethodName, false); } } string writeInvocation = context.BuildCodeString(cw => { if (context.Host.DesignTimeMode) { context.EnsureExpressionHelperVariable(); cw.WriteStartAssignment("__o"); } else if (context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput) { if (!String.IsNullOrEmpty(context.TargetWriterName)) { cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteToMethodName); cw.WriteSnippet(context.TargetWriterName); cw.WriteParameterSeparator(); } else { cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteMethodName); } } }); context.BufferStatementFragment(writeInvocation); context.MarkStartOfGeneratedCode(); }