18using System.Collections.Generic;
21using System.Threading.Tasks;
23using YamlDotNet.Core.Events;
24using YamlDotNet.Serialization;
31 public string Value {
get;
set; }
32 public bool WasQuoted {
get;
set; }
34 public CsvValue(
string value,
bool wasQuoted)
37 WasQuoted = wasQuoted;
41 internal class CsvValueYamlConverter : IYamlTypeConverter
43 public bool Accepts(Type type) => type == typeof(
CsvValue);
45 public object ReadYaml(IParser parser, Type type)
47 var value = parser.Consume<Scalar>().Value;
48 bool wasQuoted = value.StartsWith(
"\"") && value.EndsWith(
"\"");
49 if (wasQuoted) value = value.Trim(
'"');
50 return new CsvValue(value, wasQuoted);
53 public void WriteYaml(IEmitter emitter,
object value, Type type)
55 var csvValue = (CsvValue)value;
56 var scalarStyle = csvValue.WasQuoted ? ScalarStyle.DoubleQuoted : ScalarStyle.Plain;
57 emitter.Emit(
new Scalar(AnchorName.Empty, TagName.Empty, csvValue.Value, scalarStyle, !csvValue.WasQuoted, csvValue.WasQuoted));
60 public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
62 var scalarValue = parser.Consume<Scalar>().Value;
63 bool wasQuoted = scalarValue.StartsWith(
"\"") && scalarValue.EndsWith(
"\"");
64 if (wasQuoted) scalarValue = scalarValue.Trim(
'"');
65 return new CsvValue(scalarValue, wasQuoted);
68 public void WriteYaml(IEmitter emitter,
object value, Type type, ObjectSerializer serializer)
70 var csvValue = (CsvValue)value;
71 var scalarStyle = csvValue.WasQuoted ? ScalarStyle.DoubleQuoted : ScalarStyle.Plain;
72 emitter.Emit(
new Scalar(AnchorName.Empty, TagName.Empty, csvValue.Value, scalarStyle, !csvValue.WasQuoted, csvValue.WasQuoted));