public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
        {
            var chunk = context.ChunkTreeBuilder.StartParentChunk <DynamicCodeAttributeChunk>(target);

            chunk.Start  = ValueStart;
            chunk.Prefix = Prefix;
        }
示例#2
0
        public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
        {
            var chunk = context.ChunkTreeBuilder.StartParentChunk <CodeAttributeChunk>(target);

            chunk.Attribute = Name;
            chunk.Prefix    = Prefix;
            chunk.Suffix    = Suffix;
        }
        public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
        {
            var chunk = context.ChunkTreeBuilder.StartParentChunk<CodeAttributeChunk>(target);

            chunk.Attribute = Name;
            chunk.Prefix = Prefix;
            chunk.Suffix = Suffix;
        }
        public override void GenerateChunk(Span target, ChunkGeneratorContext context)
        {
            var ns = Namespace;

            if (!string.IsNullOrEmpty(ns) && char.IsWhiteSpace(ns[0]))
            {
                ns = ns.Substring(1);
            }

            context.ChunkTreeBuilder.AddUsingChunk(ns, target);
        }
        public override void GenerateChunk(Span target, ChunkGeneratorContext context)
        {
            var ns = Namespace;

            if (!string.IsNullOrEmpty(ns) && char.IsWhiteSpace(ns[0]))
            {
                ns = ns.Substring(1);
            }

            context.ChunkTreeBuilder.AddUsingChunk(ns, target);
        }
 /// <summary>
 /// Generates <see cref="AddTagHelperChunk"/>s if <see cref="RemoveTagHelperDescriptors"/> is
 /// <c>true</c>, otherwise <see cref="RemoveTagHelperChunk"/>s are generated.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Span"/> responsible for this <see cref="AddOrRemoveTagHelperChunkGenerator"/>.
 /// </param>
 /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
 /// the current chunk generation process.</param>
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     if (RemoveTagHelperDescriptors)
     {
         context.ChunkTreeBuilder.AddRemoveTagHelperChunk(LookupText, target);
     }
     else
     {
         context.ChunkTreeBuilder.AddAddTagHelperChunk(LookupText, target);
     }
 }
 /// <summary>
 /// Generates <see cref="AddTagHelperChunk"/>s if <see cref="RemoveTagHelperDescriptors"/> is
 /// <c>true</c>, otherwise <see cref="RemoveTagHelperChunk"/>s are generated.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Span"/> responsible for this <see cref="AddOrRemoveTagHelperChunkGenerator"/>.
 /// </param>
 /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
 /// the current chunk generation process.</param>
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     if (RemoveTagHelperDescriptors)
     {
         context.ChunkTreeBuilder.AddRemoveTagHelperChunk(LookupText, target);
     }
     else
     {
         context.ChunkTreeBuilder.AddAddTagHelperChunk(LookupText, target);
     }
 }
        /// <summary>
        /// Starts the generation of a <see cref="TagHelperChunk"/>.
        /// </summary>
        /// <param name="target">
        /// The <see cref="Block"/> responsible for this <see cref="TagHelperChunkGenerator"/>.
        /// </param>
        /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
        /// the current chunk generation process.</param>
        public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
        {
            var tagHelperBlock = target as TagHelperBlock;

            Debug.Assert(
                tagHelperBlock != null,
                $"A {nameof(TagHelperChunkGenerator)} must only be used with {nameof(TagHelperBlock)}s.");

            var attributes = new List <KeyValuePair <string, Chunk> >();

            // We need to create a chunk generator to create chunks for each of the attributes.
            var chunkGenerator = context.Host.CreateChunkGenerator(
                context.ClassName,
                context.RootNamespace,
                context.SourceFile);

            foreach (var attribute in tagHelperBlock.Attributes)
            {
                ParentChunk attributeChunkValue = null;

                if (attribute.Value != null)
                {
                    // Populates the chunk tree with chunks associated with attributes
                    attribute.Value.Accept(chunkGenerator);

                    var chunks = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree.Chunks;
                    var first  = chunks.FirstOrDefault();

                    attributeChunkValue = new ParentChunk
                    {
                        Association = first?.Association,
                        Children    = chunks,
                        Start       = first == null ? SourceLocation.Zero : first.Start
                    };
                }

                attributes.Add(new KeyValuePair <string, Chunk>(attribute.Key, attributeChunkValue));

                // Reset the chunk tree builder so we can build a new one for the next attribute
                chunkGenerator.Context.ChunkTreeBuilder = new ChunkTreeBuilder();
            }

            var unprefixedTagName = tagHelperBlock.TagName.Substring(_tagHelperDescriptors.First().Prefix.Length);

            context.ChunkTreeBuilder.StartParentChunk(
                new TagHelperChunk(
                    unprefixedTagName,
                    tagHelperBlock.TagMode,
                    attributes,
                    _tagHelperDescriptors),
                target,
                topLevel: false);
        }
        /// <summary>
        /// Starts the generation of a <see cref="TagHelperChunk"/>.
        /// </summary>
        /// <param name="target">
        /// The <see cref="Block"/> responsible for this <see cref="TagHelperChunkGenerator"/>.
        /// </param>
        /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
        /// the current chunk generation process.</param>
        public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
        {
            var tagHelperBlock = target as TagHelperBlock;

            Debug.Assert(
                tagHelperBlock != null,
                $"A {nameof(TagHelperChunkGenerator)} must only be used with {nameof(TagHelperBlock)}s.");

            var attributes = new List<KeyValuePair<string, Chunk>>();

            // We need to create a chunk generator to create chunks for each of the attributes.
            var chunkGenerator = context.Host.CreateChunkGenerator(
                context.ClassName,
                context.RootNamespace,
                context.SourceFile);

            foreach (var attribute in tagHelperBlock.Attributes)
            {
                ParentChunk attributeChunkValue = null;

                if (attribute.Value != null)
                {
                    // Populates the chunk tree with chunks associated with attributes
                    attribute.Value.Accept(chunkGenerator);

                    var chunks = chunkGenerator.Context.ChunkTreeBuilder.ChunkTree.Chunks;
                    var first = chunks.FirstOrDefault();

                    attributeChunkValue = new ParentChunk
                    {
                        Association = first?.Association,
                        Children = chunks,
                        Start = first == null ? SourceLocation.Zero : first.Start
                    };
                }

                attributes.Add(new KeyValuePair<string, Chunk>(attribute.Key, attributeChunkValue));

                // Reset the chunk tree builder so we can build a new one for the next attribute
                chunkGenerator.Context.ChunkTreeBuilder = new ChunkTreeBuilder();
            }

            var unprefixedTagName = tagHelperBlock.TagName.Substring(_tagHelperDescriptors.First().Prefix.Length);

            context.ChunkTreeBuilder.StartParentChunk(
                new TagHelperChunk(
                    unprefixedTagName,
                    tagHelperBlock.TagMode,
                    attributes,
                    _tagHelperDescriptors),
                target,
                topLevel: false);
        }
示例#10
0
 private void EnsureContextInitialized()
 {
     if (_context == null)
     {
         _context = new ChunkGeneratorContext(Host,
                                             ClassName,
                                             RootNamespaceName,
                                             SourceFileName,
                                             GenerateLinePragmas);
         Initialize(_context);
     }
 }
示例#11
0
        public override void GenerateChunk(Span target, ChunkGeneratorContext context)
        {
            // Check if the host supports it
            if (string.IsNullOrEmpty(context.Host.GeneratedClassContext.ResolveUrlMethodName))
            {
                // Nope, just use the default MarkupChunkGenerator behavior
                new MarkupChunkGenerator().GenerateChunk(target, context);
                return;
            }

            context.ChunkTreeBuilder.AddResolveUrlChunk(target.Content, target);
        }
示例#12
0
 private void EnsureContextInitialized()
 {
     if (_context == null)
     {
         _context = new ChunkGeneratorContext(Host,
                                              ClassName,
                                              RootNamespaceName,
                                              SourceFileName,
                                              GenerateLinePragmas);
         Initialize(_context);
     }
 }
示例#13
0
        public override void GenerateChunk(Span target, ChunkGeneratorContext context)
        {
            // Check if the host supports it
            if (string.IsNullOrEmpty(context.Host.GeneratedClassContext.ResolveUrlMethodName))
            {
                // Nope, just use the default MarkupChunkGenerator behavior
                new MarkupChunkGenerator().GenerateChunk(target, context);
                return;
            }

            context.ChunkTreeBuilder.AddResolveUrlChunk(target.Content, target);
        }
        public override void GenerateChunk(Span target, ChunkGeneratorContext context)
        {
            var chunk = context.ChunkTreeBuilder.StartParentChunk<LiteralCodeAttributeChunk>(target);
            chunk.Prefix = Prefix;
            chunk.Value = Value;

            if (ValueGenerator != null)
            {
                chunk.ValueLocation = ValueGenerator.Location;

                ValueGenerator.Value.GenerateChunk(target, context);

                chunk.ValueLocation = ValueGenerator.Location;
            }

            context.ChunkTreeBuilder.EndParentChunk();
        }
示例#15
0
        public override void GenerateChunk(Span target, ChunkGeneratorContext context)
        {
            var chunk = context.ChunkTreeBuilder.StartParentChunk <LiteralCodeAttributeChunk>(target);

            chunk.Prefix = Prefix;
            chunk.Value  = Value;

            if (ValueGenerator != null)
            {
                chunk.ValueLocation = ValueGenerator.Location;

                ValueGenerator.Value.GenerateChunk(target, context);

                chunk.ValueLocation = ValueGenerator.Location;
            }

            context.ChunkTreeBuilder.EndParentChunk();
        }
        public void RenderAttributeValue_RendersModelExpressionsCorrectly(
            string modelExpressionType,
            string propertyType,
            string expectedValue)
        {
            // Arrange
            var renderer = new MvcTagHelperAttributeValueCodeRenderer(
                new GeneratedTagHelperAttributeContext
                {
                    ModelExpressionTypeName = modelExpressionType,
                    CreateModelExpressionMethodName = "SomeMethod"
                });
            var attributeDescriptor = new TagHelperAttributeDescriptor
            {
                Name = "MyAttribute",
                PropertyName = "SomeProperty",
                TypeName = propertyType,
            };
            var writer = new CSharpCodeWriter();
            var generatorContext = new ChunkGeneratorContext(
                host: null,
                className: string.Empty,
                rootNamespace: string.Empty,
                sourceFile: string.Empty,
                shouldGenerateLinePragmas: true);
            var errorSink = new ErrorSink();
            var context = new CodeGeneratorContext(generatorContext, errorSink);

            // Act
            renderer.RenderAttributeValue(attributeDescriptor, writer, context,
            (codeWriter) =>
            {
                codeWriter.Write("MyValue");
            },
            complexValue: false);

            // Assert
            Assert.Equal(expectedValue, writer.GenerateCode());
        }
示例#17
0
 protected virtual void Initialize(ChunkGeneratorContext context)
 {
 }
示例#18
0
 public CSharpCodeWriter WriteStartInstrumentationContext(
     ChunkGeneratorContext context,
     int absoluteIndex,
     int length,
     bool isLiteral)
 {
     WriteStartMethodInvocation(context.Host.GeneratedClassContext.BeginContextMethodName);
     Write(absoluteIndex.ToString(CultureInfo.InvariantCulture));
     WriteParameterSeparator();
     Write(length.ToString(CultureInfo.InvariantCulture));
     WriteParameterSeparator();
     Write(isLiteral ? "true" : "false");
     return WriteEndMethodInvocation();
 }
        public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
        {
            var chunk = context.ChunkTreeBuilder.StartParentChunk <SectionChunk>(target);

            chunk.Name = SectionName;
        }
示例#20
0
 public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.EndParentChunk();
 }
示例#21
0
 protected virtual void Initialize(ChunkGeneratorContext context)
 {
 }
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddSetBaseTypeChunk(GetBaseType(context, BaseType), target);
 }
示例#23
0
 public void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
 }
示例#24
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="CodeGeneratorContext"/> object.
 /// </summary>
 /// <param name="generatorContext">A <see cref="ChunkGeneratorContext"/> to copy information from.</param>
 /// <param name="errorSink">
 /// The <see cref="ErrorSink"/> used to collect <see cref="RazorError"/>s encountered
 /// when parsing the current Razor document.
 /// </param>
 public CodeGeneratorContext(ChunkGeneratorContext generatorContext, ErrorSink errorSink)
     : base(generatorContext)
 {
     ErrorSink = errorSink;
     ExpressionRenderingMode = ExpressionRenderingMode.WriteToOutput;
 }
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddTypeMemberChunk(target.Content, target);
 }
 /// <summary>
 /// Generates <see cref="TagHelperPrefixDirectiveChunk"/>s.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Span"/> responsible for this <see cref="TagHelperPrefixDirectiveChunkGenerator"/>.
 /// </param>
 /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
 /// the current chunk generation process.</param>
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddTagHelperPrefixDirectiveChunk(Prefix, target);
 }
 public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
     var chunk = context.ChunkTreeBuilder.StartParentChunk<DynamicCodeAttributeChunk>(target);
     chunk.Start = ValueStart;
     chunk.Prefix = Prefix;
 }
示例#28
0
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     var modelChunk = new ModelChunk(BaseType, ModelType);
     context.ChunkTreeBuilder.AddChunk(modelChunk, target, topLevel: true);
 }
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddSetBaseTypeChunk(BaseType, target);
 }
示例#30
0
 public virtual void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
 }
 public void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.StartParentChunk<ExpressionBlockChunk>(target);
 }
示例#32
0
 /// <summary>
 /// Generates <see cref="TagHelperPrefixDirectiveChunk"/>s.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Span"/> responsible for this <see cref="TagHelperPrefixDirectiveChunkGenerator"/>.
 /// </param>
 /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
 /// the current chunk generation process.</param>
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddTagHelperPrefixDirectiveChunk(Prefix, target);
 }
示例#33
0
 public void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
 {
 }
示例#34
0
 public void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
 }
 /// <summary>
 /// Generates <see cref="RemoveTagHelperChunk"/>s.
 /// </summary>
 /// <param name="target">
 /// The <see cref="Span"/> responsible for this <see cref="RemoveTagHelperChunkGenerator"/>.
 /// </param>
 /// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
 /// the current chunk generation process.</param>
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddRemoveTagHelperChunk(_lookupText, target);
 }
 private string GetBaseType(ChunkGeneratorContext context, string baseType)
示例#37
0
 public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.EndParentChunk();
 }
示例#38
0
 public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.StartParentChunk <TemplateChunk>(target);
 }
示例#39
0
 public void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddExpressionChunk(target.Content, target);
 }
示例#40
0
        public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
        {
            var chunk = context.ChunkTreeBuilder.StartParentChunk<SectionChunk>(target);

            chunk.Name = SectionName;
        }
 public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.StartParentChunk<TemplateChunk>(target);
 }
 public void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddExpressionChunk(target.Content, target);
 }
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddStatementChunk(target.Content, target);
 }
示例#44
0
 public CSharpCodeWriter WriteStartInstrumentationContext(
     ChunkGeneratorContext context,
     SyntaxTreeNode syntaxNode,
     bool isLiteral)
 {
     return WriteStartInstrumentationContext(
         context,
         syntaxNode.Start.AbsoluteIndex,
         syntaxNode.Length,
         isLiteral);
 }
示例#45
0
 public void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.StartParentChunk <ExpressionBlockChunk>(target);
 }
示例#46
0
 public CSharpCodeWriter WriteEndInstrumentationContext(ChunkGeneratorContext context)
 {
     return WriteMethodInvocation(context.Host.GeneratedClassContext.EndContextMethodName);
 }
示例#47
0
 public void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
 {
 }
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     var injectChunk = new InjectChunk(TypeName, PropertyName);
     context.ChunkTreeBuilder.AddChunk(injectChunk, target);
 }
示例#49
0
 public virtual void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
 }