コード例 #1
0
 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);
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 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);
     }
 }