I' like to use C# type, not YAML type. YAML型ではなくC#の型を使いたい

Jul 16, 2013 at 11:41 AM
Hi there
こんにちは

The developer is Japanese, so I also write by Japanese.
開発者が日本の方なので日本語も合わせて記載します。

It is the YAML file below
まず、YAMLファイルの中身です。

%YAML 1.2

!<tag:clarkevans.com,2002:invoice>
date: 2001-01-23
invoice: 3843


このコードからinvoiceの値である3843を取得したいので、以下のコードを書きました。
I' d liket to the value of invoice. so I wrote the code bwlow.

YamlNode[] nodes = YamlNode.FromYamlFile("invoice.yaml");
YamlMapping map = (YamlMapping)nodes[0];
Console.Write("invoice: " + map["invoice"]);

しかしながら、以下のように!!intのようなYAML型も記載されてしまいます。
However, it shows the value with "YAML type" string.

!!int "3843"

C#の型として取得するメソッドはあれば教えて下さい。
If the method which pick up the type as C# exists, could you tell me the method name?
Jul 17, 2013 at 3:39 AM
I also suffer from this problem.

when i read integer type from YAML file, return value is always !!int "3843".
So, I really felt complex. I hope to receive feedback as soon as possible.
Jul 17, 2013 at 11:00 AM
I got it!
After try using YamlSerialize of Deserialize method , problem resolved.
Coordinator
Jul 17, 2013 at 12:05 PM
Excuse me for the late reply.
I'm glad you already solve the problem.

I made a link from the Documentation page to the tutorial on the top page.
Hope it helps.
Jul 18, 2013 at 4:26 AM
Hi osamu

I know the Documentation but, I hope emphasize to trim the "!!int" in the document.
Thank you.
Coordinator
Jul 19, 2013 at 2:31 AM
I modified the top page.
What is this for?
This class library supports YAML file manipulation in two different contexts.

   - One is to serialize / deserialize C# native objects into / from YAML 1.2 text files. 
    (Most of you need this.) => YamlSerizlizer class
   - The other is to manipulate generic YAML 1.2 documents that does not represent 
    C# object but does some unknown logical data. (You rarely need this.) => YamlNode class
and
YamlNode class

For the second purpose, System.Yaml.YamlNode class and its descendant classes give the 
representation of YAML's data nodes.

If you do not know the exact structure of a YAML document and it might contain a special
data tag that do not corresponds to a concrete C# class, you need to go this way.
Although YamlNode is flexible, you have to convert the YamlNodes to C# objects BY YOURSELVES.
So, if you can use YamlSerizlizer class instead, do so because it's easier.
I also point out that in the document at [System.Yaml.YamlNode > Extraction of C# native object from YamlScalar],
saids that
Extraction of C# native object from YamlScalar

If YamlScalar has a YAML's standard tag, such as !!int and !!bool, and a valid value, 
NativeObjectAvailable property is set true.
In such a case, the native object can be read from its NativeObject property.
If you have any idea that further improve documentation, let me know.
Thank you!