18using System.Collections.Generic;
21using System.Threading.Tasks;
23using YamlDotNet.Core.Events;
24using YamlDotNet.Serialization;
28 internal class QuotedString
30 public string Value {
get;
set; }
31 public bool WasQuoted {
get;
set; }
33 public QuotedString(
string value,
bool wasQuoted)
36 WasQuoted = wasQuoted;
40 internal class QuotedStringYamlConverter : IYamlTypeConverter
42 public bool Accepts(Type type) => type == typeof(QuotedString);
44 public object ReadYaml(IParser parser, Type type)
46 var value = parser.Consume<Scalar>().Value;
47 bool wasQuoted = value.StartsWith(
"\"") && value.EndsWith(
"\"");
48 if (wasQuoted) value = value.Trim(
'"');
49 return new QuotedString(value, wasQuoted);
52 public void WriteYaml(IEmitter emitter,
object value, Type type)
54 var quotedString = (QuotedString)value;
55 var scalarStyle = quotedString.WasQuoted ? ScalarStyle.DoubleQuoted : ScalarStyle.Plain;
56 emitter.Emit(
new Scalar(AnchorName.Empty, TagName.Empty, quotedString.Value, scalarStyle, !quotedString.WasQuoted, quotedString.WasQuoted));
59 public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
61 var scalarValue = parser.Consume<Scalar>().Value;
62 bool wasQuoted = scalarValue.StartsWith(
"\"") && scalarValue.EndsWith(
"\"");
63 if (wasQuoted) scalarValue = scalarValue.Trim(
'"');
64 return new QuotedString(scalarValue, wasQuoted);
67 public void WriteYaml(IEmitter emitter,
object value, Type type, ObjectSerializer serializer)
69 var quotedString = (QuotedString)value;
70 var scalarStyle = quotedString.WasQuoted ? ScalarStyle.DoubleQuoted : ScalarStyle.Plain;
71 emitter.Emit(
new Scalar(AnchorName.Empty, TagName.Empty, quotedString.Value, scalarStyle, !quotedString.WasQuoted, quotedString.WasQuoted));