コード例 #1
0
        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;
        }
コード例 #3
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;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 /// <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);
     }
 }
コード例 #7
0
 /// <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);
     }
 }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        /// <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
ファイル: RazorChunkGenerator.cs プロジェクト: jgglg/Razor
 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);
        }
コード例 #14
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();
        }
コード例 #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();
        }
コード例 #16
0
        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
ファイル: CSharpCodeWriter.cs プロジェクト: leloulight/Razor
 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();
 }
コード例 #19
0
        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
ファイル: RazorChunkGenerator.cs プロジェクト: jgglg/Razor
 protected virtual void Initialize(ChunkGeneratorContext context)
 {
 }
コード例 #22
0
 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;
 }
コード例 #25
0
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddTypeMemberChunk(target.Content, target);
 }
コード例 #26
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);
 }
コード例 #27
0
 public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
     var chunk = context.ChunkTreeBuilder.StartParentChunk<DynamicCodeAttributeChunk>(target);
     chunk.Start = ValueStart;
     chunk.Prefix = Prefix;
 }
コード例 #28
0
ファイル: ModelChunkGenerator.cs プロジェクト: notami18/Mvc
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     var modelChunk = new ModelChunk(BaseType, ModelType);
     context.ChunkTreeBuilder.AddChunk(modelChunk, target, topLevel: true);
 }
コード例 #29
0
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddSetBaseTypeChunk(BaseType, target);
 }
コード例 #30
0
 public virtual void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
 }
コード例 #31
0
 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)
 {
 }
コード例 #35
0
 /// <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);
 }
コード例 #36
0
 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;
        }
コード例 #41
0
 public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.StartParentChunk<TemplateChunk>(target);
 }
コード例 #42
0
 public void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddExpressionChunk(target.Content, target);
 }
コード例 #43
0
 public override void GenerateChunk(Span target, ChunkGeneratorContext context)
 {
     context.ChunkTreeBuilder.AddStatementChunk(target.Content, target);
 }
コード例 #44
0
ファイル: CSharpCodeWriter.cs プロジェクト: leloulight/Razor
 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
ファイル: CSharpCodeWriter.cs プロジェクト: leloulight/Razor
 public CSharpCodeWriter WriteEndInstrumentationContext(ChunkGeneratorContext context)
 {
     return WriteMethodInvocation(context.Host.GeneratedClassContext.EndContextMethodName);
 }
コード例 #47
0
 public void GenerateEndParentChunk(Block target, ChunkGeneratorContext context)
 {
 }
コード例 #48
0
 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)
 {
 }