-
-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty line in comments #926
Comments
You would need to create your own Emitter that inherits the current emitter and expose the text writer and use that to output the new line. Here's an example: using YamlDotNet.Core;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.EventEmitters;
var serializer = new SerializerBuilder().WithEventEmitter((emitter) => new TestChainedEmitter(emitter), (registration)=>registration.OnTop()).Build();
var data = new List<TestClass>
{
new TestClass() { Name = "name 1", Description = "description 1" },
new TestClass() { Name = "name 2", Description = "description 2" }
};
var stringWriter = new StringWriter();
var emitterSettings = new EmitterSettings();
var myEmitter = new MyEmitter(stringWriter, emitterSettings);
serializer.Serialize(myEmitter, data);
Console.WriteLine(stringWriter.ToString());
class TestClass
{
public string Name { get; set; }
public string Description { get; set; }
}
class TestChainedEmitter : ChainedEventEmitter
{
public TestChainedEmitter(IEventEmitter nextEmitter) : base(nextEmitter)
{
}
public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
{
(emitter as MyEmitter)?.Output.WriteLine();
base.Emit(eventInfo, emitter);
}
}
class MyEmitter : Emitter
{
public TextWriter Output { get; }
public MyEmitter(TextWriter output) : base(output)
{
Output = output;
}
public MyEmitter(TextWriter output, int bestIndent) : base(output, bestIndent)
{
Output = output;
}
public MyEmitter(TextWriter output, EmitterSettings settings) : base(output, settings)
{
Output = output;
}
public MyEmitter(TextWriter output, int bestIndent, int bestWidth) : base(output, bestIndent, bestWidth)
{
Output = output;
}
public MyEmitter(TextWriter output, int bestIndent, int bestWidth, bool isCanonical) : base(output, bestIndent, bestWidth, isCanonical)
{
Output = output;
}
} Outputs:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I try to generate an empty line using ChainedObjectGraphVisitor, but does not works, any idea how to accomplish this?
I also tried to use
[YamlMember(Description = "\nGeneral configuration")]
but don't work either.Regards
The text was updated successfully, but these errors were encountered: