Skip to content

Commit 8361c98

Browse files
committed
(maint) Fix YamlDotNet serializer
In the previous version of YamlDotNet, the Newline property of the TextWriter was used to control whether a comment was included in the output, however, this no longer seems to be respected in the latest version of YamlDotNet. Instead, make use of the WithNewLine method, and conditionally set this based on when it is called.
1 parent e78e2ec commit 8361c98

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/GitReleaseManager.Core/Configuration/ConfigSerializer.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,23 @@ public static Config Read(TextReader reader)
3636
}
3737

3838
public static void Write(Config config, TextWriter writer)
39+
{
40+
Write(config, writer, newLine: string.Empty);
41+
}
42+
43+
public static void Write(Config config, TextWriter writer, string newLine)
3944
{
4045
_logger.Debug("Starting serializing yaml configuration...");
4146
var serializerBuilder = new SerializerBuilder()
4247
.WithTypeInspector(inner => new CommentGatheringTypeInspector(inner))
4348
.WithEmissionPhaseObjectGraphVisitor(args => new CommentsObjectGraphVisitor(args.InnerVisitor))
4449
.WithNamingConvention(HyphenatedNamingConvention.Instance);
50+
51+
if (!string.IsNullOrEmpty(newLine))
52+
{
53+
serializerBuilder = serializerBuilder.WithNewLine(newLine);
54+
}
55+
4556
var serializer = serializerBuilder.Build();
4657
serializer.Serialize(writer, config);
4758
_logger.Verbose("Successfully serialized configuration!");
@@ -67,11 +78,10 @@ public static void WriteSample(TextWriter writer)
6778
var configType = config.GetType();
6879

6980
writer.Write("#");
70-
writer.NewLine = Environment.NewLine + "#";
7181
SetConfigurationSamples(config, configType, writer);
7282

7383
_logger.Verbose("Writing sample");
74-
Write(config, writer);
84+
Write(config, writer, newLine: Environment.NewLine + "#");
7585
}
7686

7787
private static void SetConfigurationSamples(object config, Type configType, TextWriter writer)

0 commit comments

Comments
 (0)