Finding instructions for reading .yaml files using C #

Two months later: The YAML file (Eve Online blueprint.yaml), which I was trying to analyze, changed a huge deal, which also simplified the analysis with a deserializer. If someone (for some reason) would like to see the code, it was updated at https://github.com/hkraal/ParseYaml


Based on Steve Wellens comment, I adjusted the code to do fewer things at once. It did not matter in the error itself. I created another project (Example1) in my solution to check the actual example found on aaubry.net, which I referenced earlier.

This gave me the same error when using the "dynamic" key, which led to my current output: There is a difference between:

items:
    - part_no:   A4786

and

items:
    part_no:   A4786

, () , .yaml , .

, "" , yaml...


# , , , . , Yaml. - YamlBlueprint, YamlBlueprint.cs, Yaml.

github, :  https://github.com/hkraal/ParseYaml

http://www.aaubry.net/page/YamlDotNet-Documentation-Loading-a-YAML-stream , . , , myKey YamlScalarNode() , .

var items = (YamlSequenceNode)mapping.Children[new YamlScalarNode(myKey)];

, :

An unhandled exception of type 'System.InvalidCastException' occurred in yamldotnet.exe
Additional information: Unable to cast object of type 'YamlDotNet.RepresentationModel.YamlMappingNode' to type 'YamlDotNet.RepresentationModel.YamlSequenceNode'.

"items" YamlScalarNode() , , . , , .

+4
3

, . YamlScalarNode , , . , .

, Node , . , .

+3

, , , , . YamlDotNet.RepresentationModel. * , YAML . , , YAML.

YAML- , Deserializer. :

using(var reader = File.OpenText("blueprints.yaml")
{
    var deserializer = new Deserializer();
    var blueprintsById = deserializer.Deserialize<Dictionary<int, YamlBlueprint>>(reader);

    // Use the blueprintsById variable
}

, Id YamlBlueprint , :

foreach(var entry in blueprintsById)
{
    entry.Value.Id = entry.Key;
}
+4

Well, that was stupid ... it's hard to create a mapping of what only contains one element. I edited the repo related in the OP with a working example if someone runs into the same problem.

-1
source

All Articles