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); }
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); }
/// <nodooc /> public StructRecordGenerator() : base(GeneratedTargetTypeKinds.Struct) { _typeEqualityGenerator = new EqualityGenerator(); _toStringGenerator = new ToStringGenerator(); }