protected override void Visit(LiteralCodeAttributeChunk chunk) { if (chunk.Value == null) { // TODO: This is a hack, this should really be handled at the chunk generation level var dynamicCodeAttributeChunk = new DynamicCodeAttributeChunk { Children = chunk.Children, Association = chunk.Association, Prefix = chunk.Prefix, Start = chunk.Start }; Visit(dynamicCodeAttributeChunk); return; } var attributePiece = new LiteralAttributePiece { DocumentLocation = CreateMappingLocation(chunk.Start, chunk.Association.Length), Prefix = chunk.Prefix, Value = chunk.Value, }; _context.Builder.Add(attributePiece); }
protected override void Visit(DynamicCodeAttributeChunk chunk) { if (Context.Host.DesignTimeMode) { return; // Don't generate anything! } Chunk code = chunk.Children.FirstOrDefault(); ExpressionRenderingMode currentRenderingMode = Context.ExpressionRenderingMode; string currentTargetWriterName = Context.TargetWriterName; Context.TargetWriterName = ValueWriterName; Writer.WriteParameterSeparator() .WriteLine(); if (code is ExpressionChunk || code is ExpressionBlockChunk) { Writer.WriteStartMethodInvocation("Tuple.Create") .WriteLocationTaggedString(chunk.Prefix) .WriteParameterSeparator() .WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" }); Context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode; Accept(code); Writer.WriteParameterSeparator() .Write(chunk.Start.AbsoluteIndex.ToString(CultureInfo.CurrentCulture)) .WriteEndMethodInvocation(false) .WriteParameterSeparator() .WriteBooleanLiteral(false) .WriteEndMethodInvocation(false); } else { Writer.WriteStartMethodInvocation("Tuple.Create") .WriteLocationTaggedString(chunk.Prefix) .WriteParameterSeparator() .WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" }) .WriteStartNewObject(Context.Host.GeneratedClassContext.TemplateTypeName); using (Writer.BuildLambda(endLine: false, parameterNames: ValueWriterName)) { Accept(chunk.Children); } Writer.WriteEndMethodInvocation(false) .WriteParameterSeparator() .Write(chunk.Start.AbsoluteIndex.ToString(CultureInfo.CurrentCulture)) .WriteEndMethodInvocation(endLine: false) .WriteParameterSeparator() .WriteBooleanLiteral(false) .WriteEndMethodInvocation(false); } Context.TargetWriterName = currentTargetWriterName; Context.ExpressionRenderingMode = currentRenderingMode; }
protected override void Visit(DynamicCodeAttributeChunk chunk) { var value = new CSharpBlock(); using (_context.Builder.UseBlock(value)) { Accept(chunk.Children); } var attributePiece = new ConditionalAttributePiece { DocumentLocation = CreateMappingLocation(chunk.Start, chunk.Association.Length), Prefix = chunk.Prefix, Value = value }; _context.Builder.Add(attributePiece); }
protected override void Visit(DynamicCodeAttributeChunk chunk) { }
protected virtual void Visit(DynamicCodeAttributeChunk chunk) { }
protected override void Visit(DynamicCodeAttributeChunk chunk) { if (Context.Host.DesignTimeMode) { // Render the children as is without wrapping them in calls to WriteAttribute Accept(chunk.Children); return; } var currentRenderingMode = Context.ExpressionRenderingMode; var currentTargetWriterName = Context.TargetWriterName; CSharpLineMappingWriter lineMappingWriter = null; var code = chunk.Children.FirstOrDefault(); if (code is ExpressionChunk || code is ExpressionBlockChunk) { // We only want to render the #line pragma if the attribute value will be in-lined. // Ex: WriteAttributeValue("", 0, DateTime.Now, 0, 0, false) // For non-inlined scenarios: WriteAttributeValue("", 0, (_) => ..., 0, 0, false) // the line pragma will be generated inside the lambda. lineMappingWriter = new CSharpLineMappingWriter(Writer, chunk.Start, Context.SourceFile); } if (!string.IsNullOrEmpty(currentTargetWriterName)) { Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteAttributeValueToMethodName) .Write(currentTargetWriterName) .WriteParameterSeparator(); } else { Writer.WriteStartMethodInvocation(WriteAttributeValueMethodName); } Context.TargetWriterName = ValueWriterName; if (code is ExpressionChunk || code is ExpressionBlockChunk) { Debug.Assert(lineMappingWriter != null); Writer .WriteLocationTaggedString(chunk.Prefix) .WriteParameterSeparator(); Context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode; Accept(code); Writer .WriteParameterSeparator() .Write(chunk.Start.AbsoluteIndex.ToString(CultureInfo.InvariantCulture)) .WriteParameterSeparator() .Write(chunk.Association.Length.ToString(CultureInfo.InvariantCulture)) .WriteParameterSeparator() .WriteBooleanLiteral(value: false) .WriteEndMethodInvocation(); lineMappingWriter.Dispose(); } else { Writer .WriteLocationTaggedString(chunk.Prefix) .WriteParameterSeparator() .WriteStartNewObject(Context.Host.GeneratedClassContext.TemplateTypeName); using (Writer.BuildAsyncLambda(endLine: false, parameterNames: ValueWriterName)) { Accept(chunk.Children); } Writer .WriteEndMethodInvocation(false) .WriteParameterSeparator() .Write(chunk.Start.AbsoluteIndex.ToString(CultureInfo.InvariantCulture)) .WriteParameterSeparator() .Write(chunk.Association.Length.ToString(CultureInfo.InvariantCulture)) .WriteParameterSeparator() .WriteBooleanLiteral(false) .WriteEndMethodInvocation(); } Context.TargetWriterName = currentTargetWriterName; Context.ExpressionRenderingMode = currentRenderingMode; }
protected abstract void Visit(DynamicCodeAttributeChunk chunk);