YamlDotNet
YamlDotNet copied to clipboard
Add format option to YamlMember to define Flow/Block serialization
I have the following class:
public class Post {
public Int32 Id { get; set; }
public String Title { get; set; }
public List<String> Tags { get; set; }
public List<Author> Authors { get; set; }
}
public class Author {
public Int32 Id { get; set; }
public String Name { get; set; }
}
When I serialize it I get:
id: 10
title: Using YAML
tags:
- Programming
- YAML
authors:
-id: 2
name: Mary
-id: 8
name: John
I would like the property tags to be serialized as flow like:
tags: [Programming,YAML]
More control on serialization format would be great because it will help people on editing them,
Maybe adding a new option to YAMLMember as follows:
[YamlMember(Format = Flow)]
Does this make sense?
I agree that this would be helpful to be able to set the SequenceStyle / MappingStyle. I just don't know what name to give to that property. It seems redundant to have two properties, one for sequences and the other for mappings. Maybe the name should be the opposite of "Scalar", such as "Structure" ? Since we already have the ScalarStyle property, we would have a StructureStyle property, accepting the same values as SequenceStyle / MappingStyle. What do you think?
Maybe an attribute named YamlStyle that would accept the enum with values Flow, Block or Any which would be the default value as in MappingStyle?
I'd rather use the existing YamlMember attribute instead of adding a new one. Previously an effort was made to unify different attributes into a single one, and I don't think that we should deviate from this.
Is this problem currently solved?
I agree that this would be helpful to be able to set the
SequenceStyle/MappingStyle. I just don't know what name to give to that property. It seems redundant to have two properties, one for sequences and the other for mappings. Maybe the name should be the opposite of "Scalar", such as "Structure" ? Since we already have theScalarStyleproperty, we would have aStructureStyleproperty, accepting the same values as SequenceStyle / MappingStyle. What do you think?
i would like to use it like so:
[YamlMember(SequenceStyle = SequenceStyle.Flow)]
and
[YamlMember(MappingStyle = MappingStyle.Flow)]
Will try to impl...
Is there a more hacky way to somehow control this?