protected override void Visit(TagHelperChunk chunk) { // We only want to setup tag helper manager fields if there are tag helpers, and only once if (!_foundTagHelpers) { _foundTagHelpers = true; // We want to hide declared TagHelper fields so they cannot be stepped over via a debugger. Writer.WriteLineHiddenDirective(); // Runtime fields aren't useful during design time. if (!Context.Host.DesignTimeMode) { // Need to disable the warning "X is assigned to but never used." for the value buffer since // whether it's used depends on how a TagHelper is used. Writer.WritePragma("warning disable 0414"); WritePrivateField(_tagHelperContext.TagHelperContentTypeName, CSharpTagHelperCodeRenderer.StringValueBufferVariableName, value: null); Writer.WritePragma("warning restore 0414"); WritePrivateField(_tagHelperContext.ExecutionContextTypeName, CSharpTagHelperCodeRenderer.ExecutionContextVariableName, value: null); Writer .Write("private ") .WriteVariableDeclaration( _tagHelperContext.RunnerTypeName, CSharpTagHelperCodeRenderer.RunnerVariableName, value: null); Writer.Write("private ") .Write(_tagHelperContext.ScopeManagerTypeName) .Write(" ") .WriteStartAssignment(CSharpTagHelperCodeRenderer.ScopeManagerVariableName) .WriteStartNewObject(_tagHelperContext.ScopeManagerTypeName) .WriteEndMethodInvocation(); } } foreach (var descriptor in chunk.Descriptors) { if (!_declaredTagHelpers.Contains(descriptor.TypeName)) { _declaredTagHelpers.Add(descriptor.TypeName); WritePrivateField(descriptor.TypeName, CSharpTagHelperCodeRenderer.GetVariableName(descriptor), value: null); } } // We need to dive deeper to ensure we pick up any nested tag helpers. Accept(chunk.Children); }
public CSharpLiteralCodeVisitor( CSharpTagHelperCodeRenderer tagHelperRenderer, CSharpCodeWriter writer, CodeBuilderContext context) : base(writer, context) { // Ensure that no matter how this class is used, we don't create numerous CSharpTagHelperCodeRenderer // instances. TagHelperRenderer = tagHelperRenderer; }
protected override void Visit(TagHelperChunk chunk) { // We only want to setup tag helper manager fields if there are tag helpers, and only once if (!_foundTagHelpers) { _foundTagHelpers = true; // We want to hide declared TagHelper fields so they cannot be stepped over via a debugger. Writer.WriteLineHiddenDirective(); // Runtime fields aren't useful during design time. if (!Context.Host.DesignTimeMode) { WritePrivateField(typeof(TextWriter).FullName, CSharpTagHelperCodeRenderer.StringValueBufferVariableName, value: null); WritePrivateField(_tagHelperContext.ExecutionContextTypeName, CSharpTagHelperCodeRenderer.ExecutionContextVariableName, value: null); WritePrivateField(_tagHelperContext.RunnerTypeName, CSharpTagHelperCodeRenderer.RunnerVariableName, "new " + _tagHelperContext.RunnerTypeName + "()"); WritePrivateField(_tagHelperContext.ScopeManagerTypeName, CSharpTagHelperCodeRenderer.ScopeManagerVariableName, "new " + _tagHelperContext.ScopeManagerTypeName + "()"); } } foreach (var descriptor in chunk.Descriptors) { if (!_declaredTagHelpers.Contains(descriptor.TypeName)) { _declaredTagHelpers.Add(descriptor.TypeName); WritePrivateField(descriptor.TypeName, CSharpTagHelperCodeRenderer.GetVariableName(descriptor), value: null); } } // We need to dive deeper to ensure we pick up any nested tag helpers. Accept(chunk.Children); }
public CSharpCodeVisitor(CSharpCodeWriter writer, CodeBuilderContext context) : base(writer, context) { _paddingBuilder = new CSharpPaddingBuilder(context.Host); TagHelperRenderer = new CSharpTagHelperCodeRenderer(this, writer, context); }