寻求指导阅读.yaml文件和C# [英] Seeking guidance reading .yaml files with C#

查看:310
本文介绍了寻求指导阅读.yaml文件和C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两个月后:
中的YAML(在线前夕blueprint.yaml)文件,我试图解析改变一个巨大的交易也使得它更容易使用去解串器解析。如果有人(无论何种原因)想看到代码,它的更新上 https://github.com/hkraal/ ParseYaml

根据史蒂夫伦斯的评论,我调整了代码一下子少做的事。它没有问题,错误本身。我创建另一个项目(例1)在我的解决方案来测试aaubry.net发现实际的例子,我引用前面。

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 current conclusion: There is a difference between:

items:
    - part_no:   A4786

items:
    part_no:   A4786

第一在我(错误地)认为我可以适用于它是使用第二个语法我.yaml文件中的示例中使用。

The first is being used in the example which I (wrongly) assumed I could apply to my .yaml file which is using the second syntax.

现在它仍然是找出如何我能得到我的钥匙的'孩子'元素,在我的YAML文件中使用的语法...

Now it remains to find out how I can get the 'child' elements of my key with the syntax used in my yaml file...

由于C#是在工作中使用我开始思考一个很好的项目,了解语言的各个方面,同时具有直接的目标努力的方向。不过我打我的第一壁在我的项目解析YAML文件相当早。我的目标是建立在YamlBlueprint.cs定义,但我甚至不获取到YAML文件的末尾YamlBlueprint对象的列表。

As C# is used at work I started thinking about a nice project to learn about various aspects of the language while having a direct goal to work towards. However I'm hitting my first wall quite early in my project parsing a Yaml file. My goal is to create an List of YamlBlueprint objects as defined in YamlBlueprint.cs but I don't even get to the end of the Yaml file.

我设置在github上一个TestCase这表明了问题:
https://github.com/hkraal/ParseYaml

I've setup a testcase on github which demonstrates the problem: https://github.com/hkraal/ParseYaml

上的 http://www.aaubry.net/page/YamlDotNet-Documentation-Loading-a-YAML-stream 工作了,直到我要循环槽的项目。根据我所看到的,我应该能给出的myKey作为参数传递给YamlScalarNode()来访问它下面的项目。

The example on http://www.aaubry.net/page/YamlDotNet-Documentation-Loading-a-YAML-stream works up untill I want to loop trough the items. Based on what I see I should be able to give myKey as parameter to the YamlScalarNode() to access the items below it.

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



我流汗以下错误,如果我做的:

I'm gettting the following error if I do:

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'.

在传递项目作为参数YamlScalarNode(),它只是抱怨不是有哪个项目是可以预料的。因为我不知道在我的toughttrain是怎么了?我很想就如何进一步解决这个有点帮助。

When passing "items" as parameter to YamlScalarNode() it just complains about the item not being there which is to be expected. As I'm not sure where my toughttrain is going wrong I would love a bit assistance on how to troubleshoot this further.

推荐答案

你有太多的东西在一行代码怎么回事。在一行中创建一个新的YamlScalarNode对象,在另一行访问阵列,在其他投行所得到的对象。这样一来,你会缩小问题区域足下。

You have too much stuff going on in one line of code. Create a new YamlScalarNode object in one line, access the array in another line, cast the resultant object in another line. That way, you'll narrow down the problem area to a single step.

该消息告诉你,你是从阵列中检索YamlMappingNode,但您需要将其转换为一个YamlSequenceNode。这是不允许的,因为这两种类型都明显不相关的。

The message is telling you that you are retrieving a YamlMappingNode from the array but you are casting it to a YamlSequenceNode. Which is not allowed since the two types are obviously not related.

这篇关于寻求指导阅读.yaml文件和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆