-
-
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
Add default scalar style #827
Conversation
Hm, I don't know enough about CI here to fix the failure. Seems like an upload failed? Error uploading artifact to the storage: Remote server returned 500: Internal Server Error |
The issue with the failed build is most likely appveyor. Can you add the same with method to the staticserializerbuilder as well? Also, in your tests can you use literal strings instead of putting \r\n in them like the other tests. I’ll take a closer look later today but this looks like a good solution so far. |
: this(nextEmitter, requireTagWhenStaticAndActualTypesAreDifferent, tagMappings) | ||
private readonly ScalarStyle defaultScalarStyle; | ||
|
||
public TypeAssigningEventEmitter(IEventEmitter nextEmitter, bool requireTagWhenStaticAndActualTypesAreDifferent, IDictionary<Type, TagName> tagMappings, bool quoteNecessaryStrings, bool quoteYaml1_1Strings, ScalarStyle defaultScalarStyle = ScalarStyle.Any) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing a constructor signature is considered a breaking change. Can you create this as a new constructor with this parameter?
The breaking change with this would be if, for whatever reason, someone was using reflection to get the constructor. You would just need to add an additional one, and not change any of the others.
public class MixedFormatScalarStyleExample | ||
{ | ||
public string[] Data { get; } | ||
public MixedFormatScalarStyleExample(string[] data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's nit picky, especially in a test class, but can you add an empty line between the property and the method? That's the general standard throughout this library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
public TypeAssigningEventEmitter(IEventEmitter nextEmitter, bool requireTagWhenStaticAndActualTypesAreDifferent, IDictionary<Type, TagName> tagMappings, bool quoteNecessaryStrings, bool quoteYaml1_1Strings, ScalarStyle defaultScalarStyle) | ||
: this(nextEmitter, requireTagWhenStaticAndActualTypesAreDifferent, tagMappings, quoteNecessaryStrings, quoteYaml1_1Strings) | ||
{ | ||
this.defaultScalarStyle = defaultScalarStyle; | ||
} | ||
|
||
public TypeAssigningEventEmitter(IEventEmitter nextEmitter, bool requireTagWhenStaticAndActualTypesAreDifferent, IDictionary<Type, TagName> tagMappings, bool quoteNecessaryStrings, ScalarStyle defaultScalarStyle) | ||
: this(nextEmitter, requireTagWhenStaticAndActualTypesAreDifferent, tagMappings, quoteNecessaryStrings) | ||
{ | ||
this.defaultScalarStyle = defaultScalarStyle; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up adding 2 constructors since SerializerBuilder
and StaticSerializerBuilder
rely on 2 different existing constructors. Is that the right approach here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
This feature has been released in version 13.2.0. |
Are you looking for something different? There's 2 methods you can call on the serializer builder that will help control whether a value/key (both are just scalars in yaml) should be quoted or not.
|
Summary
Re: #714 , it is sometimes desirable to force a quotation style on all strings in a YAML document. For example, when some strings contain valid numeric literals.
This implements the suggested change from that issue by exposing the "default scalar style" as a constructor argument. Previously, this value was hard-coded to
ScalarStyle.Any
as the local valuesuggestedStyle
.Changes
YamlDotNet/Serialization
defaultScalarStyle = ScalarStyle.Any
toTypeAssigningEventEmitter
SerializerBuilder.WithDefaultScalarStyle
TypeAssigningEventEmitter
, so I copied the instantiation from the constructor and usedloc.InsteadOf<_>
to replace it.SerializerBuilder
to construct itsTypeAssigningEventEmitter
YamlDotNet.Test
SerializationRespectsDefaultScalarStyle
SingleQuote
. I can add others if necessary.MixedFormatScalarStyleExample
to helpersTo Do
StaticSerializerBuilder.WithDefaultScalarStyle
Fix #714