private void RenderBufferedAttributeValueAccessor(CSharpCodeWriter writer) { if (_designTimeMode) { // There is no value buffer in design time mode but we still want to write out a value. We write a // value to ensure the tag helper's property type is string. writer.Write("string.Empty"); } else { writer.Write(StringValueBufferVariableName); } }
public void WriterConstructedWithoutContentLengthAndSourceFile_AddsLinePragmas_OnDispose() { // Arrange var location = new SourceLocation(10, 1, 20); var expected = string.Join(Environment.NewLine, @"#line 2 ""myfile""", "Hello world", "", "#line default", "#line hidden", ""); var expectedMappings = new LineMapping( new MappingLocation(location, 30), new MappingLocation(new SourceLocation(18, 1, 0), 11)); var writer = new CSharpCodeWriter(); // Act using (var mappingWriter = new CSharpLineMappingWriter(writer, location, "myfile")) { writer.Write("Hello world"); } // Assert Assert.Equal(expected, writer.GenerateCode()); Assert.Empty(writer.LineMappingManager.Mappings); }
/// <inheritdoc /> /// <remarks>If the attribute being rendered is of the type /// <see cref="GeneratedTagHelperAttributeContext.ModelExpressionTypeName"/>, then a model expression will be /// created by calling into <see cref="GeneratedTagHelperAttributeContext.CreateModelExpressionMethodName"/>. /// </remarks> public override void RenderAttributeValue( TagHelperAttributeDescriptor attributeDescriptor, CSharpCodeWriter writer, CodeGeneratorContext codeGeneratorContext, Action<CSharpCodeWriter> renderAttributeValue, bool complexValue) { if (attributeDescriptor == null) { throw new ArgumentNullException(nameof(attributeDescriptor)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (codeGeneratorContext == null) { throw new ArgumentNullException(nameof(codeGeneratorContext)); } if (renderAttributeValue == null) { throw new ArgumentNullException(nameof(renderAttributeValue)); } if (attributeDescriptor.TypeName.Equals(_context.ModelExpressionTypeName, StringComparison.Ordinal)) { writer .WriteStartMethodInvocation(_context.CreateModelExpressionMethodName) .Write(ModelLambdaVariableName) .Write(" => "); if (!complexValue) { writer .Write(ModelLambdaVariableName) .Write("."); } renderAttributeValue(writer); writer.WriteEndMethodInvocation(endLine: false); } else { base.RenderAttributeValue( attributeDescriptor, writer, codeGeneratorContext, renderAttributeValue, complexValue); } }
private void RenderBufferedAttributeValueAccessor(CSharpCodeWriter writer) { if (_designTimeMode) { // There is no value buffer in design time mode but we still want to write out a value. We write a // value to ensure the tag helper's property type is string. writer.Write("string.Empty"); } else { writer.WriteInstanceMethodInvocation( StringValueBufferVariableName, _tagHelperContext.TagHelperContentGetContentMethodName, endLine: false, parameters: _tagHelperContext.HtmlEncoderPropertyName); } }
public void WriterConstructedWithContentLength_AddsLineMappings_OnDispose() { // Arrange var location = new SourceLocation(10, 15, 20); var expected = new LineMapping( new MappingLocation(location, 30), new MappingLocation(new SourceLocation(0, 0, 0), 11)); var writer = new CSharpCodeWriter(); // Act using (var mappingWriter = new CSharpLineMappingWriter(writer, location, 30)) { writer.Write("Hello world"); } // Assert Assert.Equal("Hello world", writer.GenerateCode()); var mapping = Assert.Single(writer.LineMappingManager.Mappings); Assert.Equal(expected, mapping); }
private void RenderBufferedAttributeValueAccessor(CSharpCodeWriter writer) { if (_designTimeMode) { // There is no value buffer in design time mode but we still want to write out a value. We write a // value to ensure the tag helper's property type is string. writer.Write("string.Empty"); } else { writer.Write(StringValueBufferVariableName); } }
private void RenderBufferedAttributeValueAccessor(CSharpCodeWriter writer) { if (_designTimeMode) { // There is no value buffer in design time mode but we still want to write out a value. We write a // value to ensure the tag helper's property type is string. writer.Write("string.Empty"); } else { writer.WriteInstanceMethodInvocation( StringValueBufferVariableName, _tagHelperContext.TagHelperContentGetContentMethodName, endLine: false, parameters: _tagHelperContext.HtmlEncoderPropertyName); } }