Skip to content
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

Fix/comment indents (and other comment-related issues) #664

Merged
merged 8 commits into from
Jul 18, 2022
Prev Previous commit
Next Next commit
Make FlowEmitter work on set of given types
  • Loading branch information
cp committed Jan 6, 2022
commit dbfc8eddcc22cb5604c0637ab8b38648090c58cb
21 changes: 15 additions & 6 deletions YamlDotNet.Test/Serialization/YamlCommentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void SerializationWithBlockComments_IndentedInBlockAndSequence_WithFlowMa
};

var serializer = new SerializerBuilder()
.WithEventEmitter(e => new FlowPersonEmitter(e))
.WithEventEmitter(e => new FlowEmitter(e, typeof(Person)))
.Build();
var result = serializer.Serialize(garage);
Output.WriteLine(result);
Expand All @@ -185,17 +185,26 @@ public void SerializationWithBlockComments_IndentedInBlockAndSequence_WithFlowMa
}

/// <summary>
/// This emits Person objects as flow mappings
/// This emits objects of given types as flow mappings
/// </summary>
public class FlowPersonEmitter : ChainedEventEmitter
public class FlowEmitter : ChainedEventEmitter
{
public FlowPersonEmitter(IEventEmitter nextEmitter) : base(nextEmitter) { }
private readonly Type[] types;

public FlowEmitter(IEventEmitter nextEmitter, params Type[] types) : base(nextEmitter)
{
this.types = types;
}

public override void Emit(MappingStartEventInfo eventInfo, IEmitter emitter)
{
if (eventInfo.Source.Type == typeof(Person))
foreach (var type in types)
{
eventInfo.Style = MappingStyle.Flow;
if (eventInfo.Source.Type == type)
{
eventInfo.Style = MappingStyle.Flow;
break;
}
}
base.Emit(eventInfo, emitter);
}
Expand Down