yamldotnet

Deserializing YAML into Custom Types

╄→гoц情女王★ 提交于 2019-12-06 01:43:08
问题 I'm currently trying to deserialize a YAML document into standard .NET objects, such as string for scalar values and Dictionary<string, object> for mappings, using YamlDotNet library. I guess that Deserializer class is the best option, but its output is object and Dictionary<object> . I tried implementing custom INodeTypeResolver like this: class MyNodeTypeResolver : INodeTypeResolver { bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType) { if (currentType == typeof

How to convert JSON to YAML using YamlDotNet

纵然是瞬间 提交于 2019-12-05 07:46:13
I am trying to convert JSON to YAML using YamlDotNet. This is the code I have: class Program { static void Main(string[] args) { var json = "{\"swagger\":\"2.0\",\"info\":{\"title\":\"UberAPI\",\"description\":\"MoveyourappforwardwiththeUberAPI\",\"version\":\"1.0.0\"},\"host\":\"api.uber.com\",\"schemes\":[\"https\"],\"basePath\":\"/v1\",\"produces\":[\"application/json\"]}"; var swaggerDocument = JsonConvert.DeserializeObject(json); var serializer = new YamlDotNet.Serialization.Serializer(); using (var writer = new StringWriter()) { serializer.Serialize(writer, swaggerDocument); var yaml =

Deserializing YAML into Custom Types

谁说我不能喝 提交于 2019-12-04 06:06:11
I'm currently trying to deserialize a YAML document into standard .NET objects, such as string for scalar values and Dictionary<string, object> for mappings, using YamlDotNet library. I guess that Deserializer class is the best option, but its output is object and Dictionary<object> . I tried implementing custom INodeTypeResolver like this: class MyNodeTypeResolver : INodeTypeResolver { bool INodeTypeResolver.Resolve(NodeEvent nodeEvent, ref Type currentType) { if (currentType == typeof(object)) { if (nodeEvent is SequenceStart) currentType = typeof(List<object>); else if (nodeEvent is

YamlDotNet can not find property

南楼画角 提交于 2019-12-02 02:25:46
I am trying to create a simple model for parsing a yaml file to my domain object using YamlDotNet . The caveat is, that I want the domain model to be readonly, so I'm attempting to solve this through inheritance and internal setters. For some reason though, the library throws an exception stating: Property 'HtmlTemplate' not found on type 'ConsoleApplication1.Repositories.YamlTemplateRepository+DeserializeableTemplate'. I am using an alias, but even scratching that, and using a test class with the right property names does not set it right. What am I doing wrong? Have I misunderstood how the

Seeking guidance reading .yaml files with C#

瘦欲@ 提交于 2019-12-01 19:20:27
Two months later: The YAML (Eve Online blueprint.yaml) file I tried to parse changed a huge deal which also made it much easier to parse using de deserializer. If someone (for whatever reason) would like to see the code, it's updated on https://github.com/hkraal/ParseYaml Based on the comment of Steve Wellens I've adjusted the code to do less things at once. It didn't matter in the error itself. I've created another project (Example1) in my solution to test the actual example found on aaubry.net I referenced to earlier. It gave me the same error when using an "dynamic" key which lead to my

Seeking guidance reading .yaml files with C#

雨燕双飞 提交于 2019-12-01 17:46:46
问题 Two months later: The YAML (Eve Online blueprint.yaml) file I tried to parse changed a huge deal which also made it much easier to parse using de deserializer. If someone (for whatever reason) would like to see the code, it's updated on https://github.com/hkraal/ParseYaml Based on the comment of Steve Wellens I've adjusted the code to do less things at once. It didn't matter in the error itself. I've created another project (Example1) in my solution to test the actual example found on aaubry

Does C# YamlDotNet library support the merge key?

谁说胖子不能爱 提交于 2019-12-01 07:17:09
I have a problem with C# YamlDotNet library http://www.aaubry.net/page/YamlDotNet Do you know if the library does support the 'Merge Key' ? http://yaml.org/type/merge.html This does not seem to work for me. In other libraries, like PyYaml the merge works fine. Edit YamlDotNet now has support for merge keys. Example : using System; using System.IO; using System.Collections.Generic; using YamlDotNet.Serialization; using YamlDotNet.Core; public class Program { public static void Main() { var yaml = @" anchor: &default key1: &myValue value1 key2: value2 alias: <<: *default key2: Overriding key2

Does C# YamlDotNet library support the merge key?

為{幸葍}努か 提交于 2019-12-01 05:18:40
问题 I have a problem with C# YamlDotNet library http://www.aaubry.net/page/YamlDotNet Do you know if the library does support the 'Merge Key' ? http://yaml.org/type/merge.html This does not seem to work for me. In other libraries, like PyYaml the merge works fine. 回答1: Edit YamlDotNet now has support for merge keys. Example: using System; using System.IO; using System.Collections.Generic; using YamlDotNet.Serialization; using YamlDotNet.Core; public class Program { public static void Main() { var

How to serialize a custom class with YamlDotNet

淺唱寂寞╮ 提交于 2019-11-30 09:43:02
问题 I'm trying to serialize a custom class with YamlDotNet library. There is my class : public class Person { string firstName; string lastName; public Person(string first, string last) { firstName = first; lastName = last; } } And there is how, I tried to serialize it : StreamWriter streamWriter = new StreamWriter("Test.txt"); Person person = new Person("toto", "titi"); Serializer serializer = new Serializer(); serializer.Serialize(streamWriter, person); But in my output file, I only have this :

How to serialize a custom class with YamlDotNet

十年热恋 提交于 2019-11-29 18:37:25
I'm trying to serialize a custom class with YamlDotNet library. There is my class : public class Person { string firstName; string lastName; public Person(string first, string last) { firstName = first; lastName = last; } } And there is how, I tried to serialize it : StreamWriter streamWriter = new StreamWriter("Test.txt"); Person person = new Person("toto", "titi"); Serializer serializer = new Serializer(); serializer.Serialize(streamWriter, person); But in my output file, I only have this : { } What I forgot to do to serialize my class ? Thanks in advance The default behavior of YamlDotNet