Example #1
0
        private void AddExecuteTagHelpers()
        {
            var executeTagHelpers = new ExecuteTagHelpers();

            _context.Builder.Add(executeTagHelpers);

            // TODO: Should we pass enough information to not render the outputiscontentmodified if statement?
        }
        private static void Render(ExecuteTagHelpers source, CSharpRenderingContext context)
        {
            context.Writer
            .Write("await ")
            .WriteStartInstanceMethodInvocation(RunnerVariableName, context.CodeLiterals.GeneratedTagHelperContext.RunnerRunAsyncMethodName)
            .Write(ExecutionContextVariableName)
            .WriteEndMethodInvocation();

            var tagHelperOutputAccessor =
                $"{ExecutionContextVariableName}.{context.CodeLiterals.GeneratedTagHelperContext.ExecutionContextOutputPropertyName}";

            context.Writer
            .Write("if (!")
            .Write(tagHelperOutputAccessor)
            .Write(".")
            .Write(context.CodeLiterals.GeneratedTagHelperContext.TagHelperOutputIsContentModifiedPropertyName)
            .WriteLine(")");

            using (context.Writer.BuildScope())
            {
                context.Writer
                .Write("await ")
                .WriteInstanceMethodInvocation(
                    ExecutionContextVariableName,
                    context.CodeLiterals.GeneratedTagHelperContext.ExecutionContextSetOutputContentAsyncMethodName);
            }

            var renderingConventions = context.GetRenderingConventions();

            renderingConventions
            .StartWriteMethod()
            .Write(tagHelperOutputAccessor)
            .WriteEndMethodInvocation()
            .WriteStartAssignment(ExecutionContextVariableName)
            .WriteInstanceMethodInvocation(
                ScopeManagerVariableName,
                context.CodeLiterals.GeneratedTagHelperContext.ScopeManagerEndMethodName);
        }