コード例 #1
0
        private string GenerateToStringMembers(Compilation compilation, INamedTypeSymbol symbol, INamedTypeSymbol attributeSymbol)
        {
            if (!ToStringGenerator.HasGenerateToStringAttribute(symbol, compilation) &&
                _toStringGenerator.CanGenerateBody(symbol, compilation: null))
            {
                return(_toStringGenerator.GenerateBody(compilation, symbol, attributeSymbol));
            }

            return(string.Empty);
        }
コード例 #2
0
        public void Generator_does_generate_ToString_method(
            string inputSourceCodeResourceName, string expectedSourceCodeResourceName)
        {
            // Arrange
            string attributeSourceCode = GetResource(ToStringGeneratorAttributeDescription.EmebeddedResourceName, typeof(ToStringGenerator).Assembly);
            string inputSourceCode     = GetResource(inputSourceCodeResourceName);
            string expectedSourceCode  = GetResource(expectedSourceCodeResourceName);

            string[] expectedSourceCodes = new[] { attributeSourceCode, expectedSourceCode };

            var compilation = CreateCompilation(inputSourceCode);

            // Act
            var sut = new ToStringGenerator();

            compilation = RunGenerators(compilation, out var diagnostics, sut);

            // Assert
            diagnostics.Should().BeEmpty();

            var generatedSourceCode = GetGeneratedCode(sut, compilation);

            AssertSourceCodesEquals(generatedSourceCode, expectedSourceCodes);
        }
コード例 #3
0
 /// <nodooc />
 public StructRecordGenerator()
     : base(GeneratedTargetTypeKinds.Struct)
 {
     _typeEqualityGenerator = new EqualityGenerator();
     _toStringGenerator     = new ToStringGenerator();
 }