This code does not work because
YamlDotNet.Core.YamlException: 'Property 'unknown1' not found.
How do I configure this correctly (if it is possible at all)
using System.Runtime.Serialization;
using YamlDotNet.RepresentationModel;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
var input = @"
Name: John
Count: 34
unknown1:
xyz: value1
abc: value2
unknown2: foo
");
var serializer = new SerializerBuilder()
.WithNamingConvention(PascalCaseNamingConvention.Instance)
.Build();
var deserializer = new DeserializerBuilder()
.WithNamingConvention(PascalCaseNamingConvention.Instance)
.Build();
public class Person {
public string Name { get; set; }
public string Count { get; set; }
// this is not a regular property, this is to record all unknown members from the yaml.
// and when serializing, the content should be serialized again on the same level
// as Name und Count.
public Dictionary<string, string> UnknownProperties { get; set; }
}
If it would work UnknownProperties should contain the following:
{"unknown1", "xyz: value1\nabc: value2"} {"unknown2", "foo"}
alternatively: Dictionary<string, object> UnknownProperties
{"unknown1", {{"xyz","value1"},{"abc", "value2"}}} {"unknown2", "foo"}
The structure of unknown1, unknown2 is not known at this time.