ToString method returns value in quotes

Mar 14, 2010 at 5:51 AM

Why ToString() method returns values in quotes?

For example:

var yaml = YamlNode.FromYaml("src: dst")[0] as YamlMapping;
foreach (var pair in yaml)

Mar 14, 2010 at 8:56 AM

Hi, Shidzo,

YamlNode.ToString() is offered mainly for debug usage.

Any YamlNode can be displayed as text by this method, even when it is not a YamlScalar
with a !!str tag. (Note that when the text expression becomes too long, it will be truncated.)

var yaml = YamlNode.FromYaml("src: dst")[0];
// => {"src": "dst"}

I thought quoting a text scalar value makes it easier to distinguish the node's content
during debug.

var yaml = YamlNode.FromYaml("src:dst")[0];
// => "src:dst"

If you want to know the scalar node's exact text expression, refer to YamlScalar.Value property.

// => src

Mar 14, 2010 at 10:18 AM

Oh, I didn't guess to convert the received key object in my example to YamlScalar and thought that ToString() is the way to get the key value. You're right, I really wanted to get an exact value of the string expression. Sorry for bothering you :)


Mar 14, 2010 at 12:14 PM

If you didn't expect receiving the key as a YamlScalar object, you might become happier with looking
into the YamlSerializer class, instead of YamlNode class.

YamlSerializer can serialize / deserialize C#'s native objects directly into / from YAML documents.


Mar 14, 2010 at 12:57 PM
Edited Mar 14, 2010 at 12:59 PM

Thank you, but YamlSerializer isn't quite suitable for my task, YamlNode is what I need.

P.S. You have misprints in some places - YamlSerizler, for example on home page and YamlSerializer page.