public override void GenerateStartParentChunk(Block target, ChunkGeneratorContext context) { var chunk = context.ChunkTreeBuilder.StartParentChunk <DynamicCodeAttributeChunk>(target); chunk.Start = ValueStart; chunk.Prefix = Prefix; }
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); }
/// <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); }
private void EnsureContextInitialized() { if (_context == null) { _context = new ChunkGeneratorContext(Host, ClassName, RootNamespaceName, SourceFileName, GenerateLinePragmas); Initialize(_context); } }
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(); }
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()); }
protected virtual void Initialize(ChunkGeneratorContext context) { }
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; }
public override void GenerateEndParentChunk(Block target, ChunkGeneratorContext context) { context.ChunkTreeBuilder.EndParentChunk(); }
public override void GenerateChunk(Span target, ChunkGeneratorContext context) { context.ChunkTreeBuilder.AddSetBaseTypeChunk(GetBaseType(context, BaseType), target); }
public void GenerateChunk(Span target, ChunkGeneratorContext context) { }
/// <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; }
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); }
public virtual void GenerateStartParentChunk(Block target, ChunkGeneratorContext context) { }
public void GenerateStartParentChunk(Block target, ChunkGeneratorContext context) { context.ChunkTreeBuilder.StartParentChunk<ExpressionBlockChunk>(target); }
public void GenerateEndParentChunk(Block 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)
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 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 override void GenerateChunk(Span target, ChunkGeneratorContext context) { context.ChunkTreeBuilder.AddStatementChunk(target.Content, target); }
public CSharpCodeWriter WriteStartInstrumentationContext( ChunkGeneratorContext context, SyntaxTreeNode syntaxNode, bool isLiteral) { return WriteStartInstrumentationContext( context, syntaxNode.Start.AbsoluteIndex, syntaxNode.Length, isLiteral); }
public void GenerateStartParentChunk(Block target, ChunkGeneratorContext context) { context.ChunkTreeBuilder.StartParentChunk <ExpressionBlockChunk>(target); }
public CSharpCodeWriter WriteEndInstrumentationContext(ChunkGeneratorContext context) { return WriteMethodInvocation(context.Host.GeneratedClassContext.EndContextMethodName); }
public override void GenerateChunk(Span target, ChunkGeneratorContext context) { var injectChunk = new InjectChunk(TypeName, PropertyName); context.ChunkTreeBuilder.AddChunk(injectChunk, target); }