System.Yaml Namespace

[image]

YAML Serializer
System.Yaml Namespace
Send Feedback

What is this for?

This class library supports YAML file manipulation in two different contexts.

  1. One is to serialize / deserialize C# native objects into / from YAML text files. => [System.Yaml.Serialization.YamlSerializer]
  2. The other is manipulating generic YAML documents that does not represents C# object but does some logical data. => [System.Yaml.YamlNode]

Requirements

.NET 3.5 SP1

What is YAML?

YAML is a human friendly data serialization standard for all programming languages.

There is a good introduction in the YAML for .NET, Visual Studio and Powershell project.

According to that,
  1. YAML is easily readable by humans.
  2. YAML is consise and compact.
  3. YAML is expressive and extensible.

Another introduction can be found at Yaml Cookbook.

See The Official YAML Web Site for the language specification.

Note that the top page of The Official YAML Web Site is written as a valid YAML 1.2 document. It is definitely human friendly.

YamlSerizlizer class

For the first purpose, System.Yaml.Serialization.YamlSerializer class has instance methods [YamlSerializer.Serialize] and [YamlSerializer.Deserialize]. With these methods, C# native objects can be converted into / from YAML text without any preparations.

CopyC#
// Simple(?) array of objects
object obj = new object[]{
    "a",
    true,
    1,
    1.0,
    new Point(1,3),
    new YamlScalar("node")
};

var serializer = new YamlSerializer();

// Serialize it. How difficult!
string yaml = serializer.Serialize( obj );

// %YAML 1.2
// ---
// - "a"
// - true
// - 1
// - !!float 1
// - !<!System.Drawing.Point> 1,3
// - !<!YamlSerializer.YamlScalar>
//   Tag: "tag:yaml.org,2002:str"
//   Value: "node"
// ...

// Deserialize it.
object restored = serializer.Deserialize(yaml)[0];

// In general, you can serialize multiple objects in a YAML stream.
// So the Deserialize method returns an array of objects.

YamlNode class

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

See [YamlScalar], [YamlSequence] and [YamlMapping] classes for the actual data classes.

To read / write YAML text to compose / present [YamlNode] tree, the static method [YamlNode.FromYaml] and the instance method [YamlNode.ToYaml] are provided.

CopyC#
YamlNode[] nodes = YamlNode.FromYaml(new System.IO.FileStream("settings.yaml"));
string yaml = nodes[0].ToYaml();

Classes

Class | Description
YamlComplexNode | Abstract base class of YamlNode that have child nodes. YamlMapping and YamlSequence inherites from this class.
YamlConfig | Configuration to customize YAML serialization. An instance of this class can be passed to the serialization methods, such as YamlNode.ToYaml(YamlConfig) and YamlNode.FromYaml(Stream,YamlConfig) or it can be assigned to YamlNode.DefaultConfig.
YamlMapping | Represents a mapping node in a YAML document. Use IDictionary<YamlNode,YamlNode> interface to manipulate child key/value pairs.
YamlNode | Abstract base class of YAML data nodes. See YamlScalar, YamlSequence and YamlMapping for actual data classes.
YamlNodeManipulator | Implements utility functions to instantiating YamlNode's
YamlScalar | Represents a scalar node in a YAML document.
YamlSequence | Represents a sequence node in a YAML document. Use IList<YamlNode> interface to manipulate child nodes.

Send comments on this topic to Osamu TAKEUCHI


YamlComplexNode Class

[image]

YAML Serializer
YamlComplexNode Class
Members See Also Send Feedback
Abstract base class of YamlNode that have child nodes. YamlMapping and YamlSequence inherites from this class.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public abstract class YamlComplexNode : YamlNode
Visual Basic (Declaration)
Public MustInherit Class YamlComplexNode _
    Inherits YamlNode
Visual C++
public ref class YamlComplexNode abstract : public YamlNode

Inheritance Hierarchy

System..::.Object
System.Yaml..::.YamlNode
System.Yaml..::.YamlComplexNode
System.Yaml..::.YamlMapping
System.Yaml..::.YamlSequence

See Also

YamlComplexNode Members
System.Yaml Namespace


YamlComplexNode Members

[image] [image]

YAML Serializer
YamlComplexNode Members
YamlComplexNode Class Constructors Methods Properties Events See Also Send Feedback

The YamlComplexNode type exposes the following members.

Constructors

Name | Description
YamlComplexNode | Initializes a new instance of the YamlComplexNode class

Methods

Name | Description
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Calculate hash code from Tag property and all child nodes. The result is cached. (Overrides YamlNode..::.GetHashCodeCore()()().)
GetHashCodeCoreSub | Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree.
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Inherited from YamlNode.)
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlComplexNode Class


YamlComplexNode Constructor

[image]

YAML Serializer
YamlComplexNode Constructor
YamlComplexNode Class See Also Send Feedback
Initializes a new instance of the YamlComplexNode class

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected YamlComplexNode()
Visual Basic (Declaration)
Protected Sub New
Visual C++
protected:
YamlComplexNode()

See Also

YamlComplexNode Class


YamlComplexNode Methods

[image] [image]

YAML Serializer
YamlComplexNode Methods
YamlComplexNode Class See Also Send Feedback

The YamlComplexNode type exposes the following members.

Methods

Name | Description
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Calculate hash code from Tag property and all child nodes. The result is cached. (Overrides YamlNode..::.GetHashCodeCore()()().)
GetHashCodeCoreSub | Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree.
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Inherited from YamlNode.)
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

See Also

YamlComplexNode Class


GetHashCodeCore Method

[image]

YAML Serializer
YamlComplexNode..::.GetHashCodeCore Method
YamlComplexNode Class See Also Send Feedback
Calculate hash code from Tag property and all child nodes. The result is cached.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected override int GetHashCodeCore()
Visual Basic (Declaration)
Protected Overrides Function GetHashCodeCore As Integer
Visual C++
protected:
virtual int GetHashCodeCore() override

Return Value

Hash value for the object.

See Also

YamlComplexNode Class


GetHashCodeCoreSub Method

[image]

YAML Serializer
YamlComplexNode..::.GetHashCodeCoreSub Method
YamlComplexNode Class See Also Send Feedback
Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected abstract int GetHashCodeCoreSub(
    int path,
    Dictionary<YamlNode, int> dict
)
Visual Basic (Declaration)
Protected MustOverride Function GetHashCodeCoreSub ( _
    path As Integer, _
    dict As Dictionary(Of YamlNode, Integer) _
) As Integer
Visual C++
protected:
virtual int GetHashCodeCoreSub(
    int path,
    Dictionary<YamlNode^, int>^ dict
) abstract

Parameters

path
Type: System..::.Int32
The cache code for the path where this node was found.
dict
Type: System.Collections.Generic..::.Dictionary <(Of <( YamlNode, Int32 >)>)
Repository of the nodes that already appeared in the node tree. Sub hash code for the nodes can be refered to from this dictionary.

Return Value

[Missing <returns> documentation for "M:System.Yaml.YamlComplexNode.GetHashCodeCoreSub(System.Int32,System.Collections.Generic.Dictionary{System.Yaml.YamlNode,System.Int32})"]

See Also

YamlComplexNode Class


ToYaml Method

[image] [image]

YAML Serializer
YamlComplexNode..::.ToYaml Method
YamlComplexNode Class See Also Send Feedback

Overload List

Name | Description
ToYaml()()() | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)
ToYaml(YamlConfig) | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream, YamlConfig) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter, YamlConfig) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)

See Also

YamlComplexNode Class
YamlComplexNode Members


ToYamlFile Method

[image] [image]

YAML Serializer
YamlComplexNode..::.ToYamlFile Method
YamlComplexNode Class See Also Send Feedback

Overload List

Name | Description
ToYamlFile(String) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)
ToYamlFile(String, YamlConfig) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)

See Also

YamlComplexNode Class
YamlComplexNode Members


YamlComplexNode Properties

[image] [image]

YAML Serializer
YamlComplexNode Properties
YamlComplexNode Class See Also Send Feedback

The YamlComplexNode type exposes the following members.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)

See Also

YamlComplexNode Class


YamlComplexNode Events

[image] [image]

YAML Serializer
YamlComplexNode Events
YamlComplexNode Class See Also Send Feedback

The YamlComplexNode type exposes the following members.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlComplexNode Class


YamlConfig Class

[image]

YAML Serializer
YamlConfig Class
Members See Also Send Feedback

Configuration to customize YAML serialization.

An instance of this class can be passed to the serialization methods, such as YamlNode.ToYaml(YamlConfig) and YamlNode.FromYaml(Stream,YamlConfig) or it can be assigned to YamlNode.DefaultConfig.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public class YamlConfig
Visual Basic (Declaration)
Public Class YamlConfig
Visual C++
public ref class YamlConfig

Inheritance Hierarchy

System..::.Object
System.Yaml..::.YamlConfig

See Also

YamlConfig Members


YamlConfig Members

[image] [image]

YAML Serializer
YamlConfig Members
YamlConfig Class Constructors Methods Fields See Also Send Feedback

The YamlConfig type exposes the following members.

Constructors

Name | Description
YamlConfig | Initializes a new instance of the YamlConfig class

Methods

Name | Description
AddActivator<(Of <(T>)>) | Add an ability of instantiating an instance of a class that has no default constructer.
AddRule<(Of <(T>)>) | Add a custom tag resolution rule.
Equals | (Inherited from Object.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Object.)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
ToString | (Inherited from Object.)

Fields

Name | Description
DontUseVerbatimTag | If true, the verbatim style of a tag, i.e. !< > is avoided as far as possible.
ExplicitlyPreserveLineBreaks | If true, all YamlScalars whose text expression contains line breaks will be presented as double quoted texts, where the line break characters are escaped by back slash as "\\n" and "\\r". The default is true.
LineBreakForInput | The YAML parser normalizes line breaks in a YAML stream to this value. "\n" is default, and is the only valid value in the YAML specification. "\r" and "\r\n" are allowed in this library for convenience. To suppress normalization of line breaks by YAML parser, set NormalizeLineBreaks false, though it is also violate the YAML specification.
LineBreakForOutput | Line break to be used when YamlNode is presented in YAML stream. "\r", "\r\n", "\n" are allowed. "\r\n" is defalut.
NormalizeLineBreaks | If true, all line breaks in the node value are normalized into "\r\n" (= LineBreakForOutput) when serialize and line breaks that are not escaped in YAML stream are normalized into "\n" (= LineBreakForInput. If false, the line breaks are preserved. Setting this option false violates the YAML specification but sometimes useful. The default is true.
OmitTagForRootNode | If true, tag for the root node is omitted by YamlSerializer.

See Also

YamlConfig Class


YamlConfig Constructor

[image]

YAML Serializer
YamlConfig Constructor
YamlConfig Class See Also Send Feedback
Initializes a new instance of the YamlConfig class

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlConfig()
Visual Basic (Declaration)
Public Sub New
Visual C++
public:
YamlConfig()

See Also

YamlConfig Class


YamlConfig Fields

[image] [image]

YAML Serializer
YamlConfig Fields
YamlConfig Class See Also Send Feedback

The YamlConfig type exposes the following members.

Fields

Name | Description
DontUseVerbatimTag | If true, the verbatim style of a tag, i.e. !< > is avoided as far as possible.
ExplicitlyPreserveLineBreaks | If true, all YamlScalars whose text expression contains line breaks will be presented as double quoted texts, where the line break characters are escaped by back slash as "\\n" and "\\r". The default is true.
LineBreakForInput | The YAML parser normalizes line breaks in a YAML stream to this value. "\n" is default, and is the only valid value in the YAML specification. "\r" and "\r\n" are allowed in this library for convenience. To suppress normalization of line breaks by YAML parser, set NormalizeLineBreaks false, though it is also violate the YAML specification.
LineBreakForOutput | Line break to be used when YamlNode is presented in YAML stream. "\r", "\r\n", "\n" are allowed. "\r\n" is defalut.
NormalizeLineBreaks | If true, all line breaks in the node value are normalized into "\r\n" (= LineBreakForOutput) when serialize and line breaks that are not escaped in YAML stream are normalized into "\n" (= LineBreakForInput. If false, the line breaks are preserved. Setting this option false violates the YAML specification but sometimes useful. The default is true.
OmitTagForRootNode | If true, tag for the root node is omitted by YamlSerializer.

See Also

YamlConfig Class


DontUseVerbatimTag Field

[image]

YAML Serializer
YamlConfig..::.DontUseVerbatimTag Field
YamlConfig Class See Also Send Feedback
If true, the verbatim style of a tag, i.e. !< > is avoided as far as possible.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool DontUseVerbatimTag
Visual Basic (Declaration)
Public DontUseVerbatimTag As Boolean
Visual C++
public:
bool DontUseVerbatimTag

See Also

YamlConfig Class


ExplicitlyPreserveLineBreaks Field

[image]

YAML Serializer
YamlConfig..::.ExplicitlyPreserveLineBreaks Field
YamlConfig Class Example See Also Send Feedback
If true, all YamlScalars whose text expression contains line breaks will be presented as double quoted texts, where the line break characters are escaped by back slash as "\\n" and "\\r". The default is true.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool ExplicitlyPreserveLineBreaks
Visual Basic (Declaration)
Public ExplicitlyPreserveLineBreaks As Boolean
Visual C++
public:
bool ExplicitlyPreserveLineBreaks

Remarks

The escaped line breaks makes the YAML stream hard to read, but is required to prevent the line break characters be normalized by the YAML parser; the YAML sepcification requires a YAML parser to normalize all line breaks that are not escaped into a single line feed "\n" when it parse a YAML source.

If the preservation of line breaks are not required, set this value false.

Then, whenever it is possible, the YamlNodes are presented as literal style text, where the line breaks are not escaped. This results in a much prettier output in the YAML stream.

Examples

CopyC#
// A string containing line breaks "\n\r" and "\r".
YamlNode node = "a\r\n  b\rcde";

// By default conversion, line breaks are escaped in a double quoted string.
var yaml = node.ToYaml();
// %YAML 1.2
// ---
// "a\r\n\
// \  b\r\
// cde"
// ...

// "%YAML 1.2\r\n---\r\n\"a\\r\\n\\\r\n\  b\\r\\\r\ncde\"\r\n...\r\n"

// Such a YAML stream is not pretty but is capable to preserve
// original line breaks even when the line breaks of the YAML stream
// are changed (for instance, by some editor) between serialization
// and deserialization.
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // still equivalent to the original

// By setting ExplicitlyPreserveLineBreaks false, the output becomes
// much prettier.
YamlNode.DefaultConfig.ExplicitlyPreserveLineBreaks = false;
yaml = node.ToYaml();
// %YAML 1.2
// ---
// |-2
//   a
//     b
//   cde
// ...

// line breaks are nomalized to "\r\n" (= YamlNode.DefaultConfig.LineBreakForOutput)
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\r\ncde\r\n...\r\n"

// line breaks are nomalized to "\n" (= YamlNode.DefaultConfig.LineBreakForInput)
var restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"

// Disable line break normalization.
YamlNode.DefaultConfig.NormalizeLineBreaks = false;
yaml = node.ToYaml();

// line breaks are not nomalized
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\rcde\r\n...\r\n"

// Unless line breaks in YAML stream is preserved, original line
// breaks can be restored.
restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"        // original line breaks are lost

See Also

YamlConfig Class


LineBreakForInput Field

[image]

YAML Serializer
YamlConfig..::.LineBreakForInput Field
YamlConfig Class Example See Also Send Feedback

The YAML parser normalizes line breaks in a YAML stream to this value.

"\n" is default, and is the only valid value in the YAML specification. "\r" and "\r\n" are allowed in this library for convenience.

To suppress normalization of line breaks by YAML parser, set NormalizeLineBreaks false, though it is also violate the YAML specification.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string LineBreakForInput
Visual Basic (Declaration)
Public LineBreakForInput As String
Visual C++
public:
String^ LineBreakForInput

Remarks

The YAML sepcification requires a YAML parser to normalize every line break that is not escaped in a YAML stream, into a single line feed "\n" when it parse a YAML stream. But this is not convenient in some cases, especially under Windows environment, where the system default line break is "\r\n" instead of "\n".

This library provides two workarounds for this problem.

One is setting NormalizeLineBreaks false. It disables the line break normalization. The line breaks are serialized into a YAML stream as is and those in the YAML stream are deserialized as is.

Another is setting LineBreakForInput "\r\n". Then, the YAML parser normalizes all line breaks into "\r\n" instead of "\n".

Note that although these two options are useful in some cases, they makes the YAML parser violate the YAML specification.

Examples

CopyC#
// A string containing line breaks "\n\r" and "\r".
YamlNode node = "a\r\n  b\rcde";

// By default conversion, line breaks are escaped in a double quoted string.
var yaml = node.ToYaml();
// %YAML 1.2
// ---
// "a\r\n\
// \  b\r\
// cde"
// ...

// "%YAML 1.2\r\n---\r\n\"a\\r\\n\\\r\n\  b\\r\\\r\ncde\"\r\n...\r\n"

// Such a YAML stream is not pretty but is capable to preserve
// original line breaks even when the line breaks of the YAML stream
// are changed (for instance, by some editor) between serialization
// and deserialization.
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // still equivalent to the original

// By setting ExplicitlyPreserveLineBreaks false, the output becomes
// much prettier.
YamlNode.DefaultConfig.ExplicitlyPreserveLineBreaks = false;
yaml = node.ToYaml();
// %YAML 1.2
// ---
// |-2
//   a
//     b
//   cde
// ...

// line breaks are nomalized to "\r\n" (= YamlNode.DefaultConfig.LineBreakForOutput)
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\r\ncde\r\n...\r\n"

// line breaks are nomalized to "\n" (= YamlNode.DefaultConfig.LineBreakForInput)
var restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"

// Disable line break normalization.
YamlNode.DefaultConfig.NormalizeLineBreaks = false;
yaml = node.ToYaml();

// line breaks are not nomalized
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\rcde\r\n...\r\n"

// Unless line breaks in YAML stream is preserved, original line
// breaks can be restored.
restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"        // original line breaks are lost

See Also

YamlConfig Class


LineBreakForOutput Field

[image]

YAML Serializer
YamlConfig..::.LineBreakForOutput Field
YamlConfig Class Example See Also Send Feedback
Line break to be used when YamlNode is presented in YAML stream. "\r", "\r\n", "\n" are allowed. "\r\n" is defalut.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string LineBreakForOutput
Visual Basic (Declaration)
Public LineBreakForOutput As String
Visual C++
public:
String^ LineBreakForOutput

Examples

CopyC#
// A string containing line breaks "\n\r" and "\r".
YamlNode node = "a\r\n  b\rcde";

// By default conversion, line breaks are escaped in a double quoted string.
var yaml = node.ToYaml();
// %YAML 1.2
// ---
// "a\r\n\
// \  b\r\
// cde"
// ...

// "%YAML 1.2\r\n---\r\n\"a\\r\\n\\\r\n\  b\\r\\\r\ncde\"\r\n...\r\n"

// Such a YAML stream is not pretty but is capable to preserve
// original line breaks even when the line breaks of the YAML stream
// are changed (for instance, by some editor) between serialization
// and deserialization.
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // still equivalent to the original

// By setting ExplicitlyPreserveLineBreaks false, the output becomes
// much prettier.
YamlNode.DefaultConfig.ExplicitlyPreserveLineBreaks = false;
yaml = node.ToYaml();
// %YAML 1.2
// ---
// |-2
//   a
//     b
//   cde
// ...

// line breaks are nomalized to "\r\n" (= YamlNode.DefaultConfig.LineBreakForOutput)
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\r\ncde\r\n...\r\n"

// line breaks are nomalized to "\n" (= YamlNode.DefaultConfig.LineBreakForInput)
var restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"

// Disable line break normalization.
YamlNode.DefaultConfig.NormalizeLineBreaks = false;
yaml = node.ToYaml();

// line breaks are not nomalized
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\rcde\r\n...\r\n"

// Unless line breaks in YAML stream is preserved, original line
// breaks can be restored.
restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"        // original line breaks are lost

See Also

YamlConfig Class


NormalizeLineBreaks Field

[image]

YAML Serializer
YamlConfig..::.NormalizeLineBreaks Field
YamlConfig Class Example See Also Send Feedback
If true, all line breaks in the node value are normalized into "\r\n" (= LineBreakForOutput) when serialize and line breaks that are not escaped in YAML stream are normalized into "\n" (= LineBreakForInput. If false, the line breaks are preserved. Setting this option false violates the YAML specification but sometimes useful. The default is true.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool NormalizeLineBreaks
Visual Basic (Declaration)
Public NormalizeLineBreaks As Boolean
Visual C++
public:
bool NormalizeLineBreaks

Remarks

The YAML sepcification requires a YAML parser to normalize every line break that is not escaped in a YAML stream, into a single line feed "\n" when it parse a YAML stream. But this is not convenient in some cases, especially under Windows environment, where the system default line break is "\r\n" instead of "\n".

This library provides two workarounds for this problem.

One is setting NormalizeLineBreaks false. It disables the line break normalization. The line breaks are serialized into a YAML stream as is and those in the YAML stream are deserialized as is.

Another is setting LineBreakForInput "\r\n". Then, the YAML parser normalizes all line breaks into "\r\n" instead of "\n".

Note that although these two options are useful in some cases, they makes the YAML parser violate the YAML specification.

Examples

CopyC#
// A string containing line breaks "\n\r" and "\r".
YamlNode node = "a\r\n  b\rcde";

// By default conversion, line breaks are escaped in a double quoted string.
var yaml = node.ToYaml();
// %YAML 1.2
// ---
// "a\r\n\
// \  b\r\
// cde"
// ...

// "%YAML 1.2\r\n---\r\n\"a\\r\\n\\\r\n\  b\\r\\\r\ncde\"\r\n...\r\n"

// Such a YAML stream is not pretty but is capable to preserve
// original line breaks even when the line breaks of the YAML stream
// are changed (for instance, by some editor) between serialization
// and deserialization.
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
var restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // still equivalent to the original

// By setting ExplicitlyPreserveLineBreaks false, the output becomes
// much prettier.
YamlNode.DefaultConfig.ExplicitlyPreserveLineBreaks = false;
yaml = node.ToYaml();
// %YAML 1.2
// ---
// |-2
//   a
//     b
//   cde
// ...

// line breaks are nomalized to "\r\n" (= YamlNode.DefaultConfig.LineBreakForOutput)
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\r\ncde\r\n...\r\n"

// line breaks are nomalized to "\n" (= YamlNode.DefaultConfig.LineBreakForInput)
var restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"

// Disable line break normalization.
YamlNode.DefaultConfig.NormalizeLineBreaks = false;
yaml = node.ToYaml();

// line breaks are not nomalized
// "%YAML 1.2\r\n---\r\n|-2\r\n  a\r\n    b\rcde\r\n...\r\n"

// Unless line breaks in YAML stream is preserved, original line
// breaks can be restored.
restored = YamlNode.FromYaml(yaml)[0];
// "a\r\n  b\rcde"      // equivalent to the original

yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
restored = YamlNode.FromYaml(yaml)[0];
// "a\n  b\ncde"        // original line breaks are lost

See Also

YamlConfig Class


OmitTagForRootNode Field

[image]

YAML Serializer
YamlConfig..::.OmitTagForRootNode Field
YamlConfig Class See Also Send Feedback
If true, tag for the root node is omitted by YamlSerializer.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool OmitTagForRootNode
Visual Basic (Declaration)
Public OmitTagForRootNode As Boolean
Visual C++
public:
bool OmitTagForRootNode

See Also

YamlConfig Class


YamlConfig Methods

[image] [image]

YAML Serializer
YamlConfig Methods
YamlConfig Class See Also Send Feedback

The YamlConfig type exposes the following members.

Methods

Name | Description
AddActivator<(Of <(T>)>) | Add an ability of instantiating an instance of a class that has no default constructer.
AddRule<(Of <(T>)>) | Add a custom tag resolution rule.
Equals | (Inherited from Object.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Object.)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
ToString | (Inherited from Object.)

See Also

YamlConfig Class


AddActivator(T) Method

[image]

YAML Serializer
YamlConfig..::.AddActivator<(Of <(T>)>) Method
YamlConfig Class Example See Also Send Feedback
Add an ability of instantiating an instance of a class that has no default constructer.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void AddActivator<T>(
    Func<Object> activator
)
where T : class
Visual Basic (Declaration)
Public Sub AddActivator(Of T As Class) ( _
    activator As Func(Of Object) _
)
Visual C++
public:
generic<typename T>
where T : ref class
void AddActivator(
    Func<Object^>^ activator
)

Parameters

activator
Type: System..::.Func <(Of <( Object >)>)
A delegate that creates an instance of T.

Type Parameters

T
Type of the object that is activated by this activator.

Examples

CopyC#
var serializer= new YamlSerializer();

var yaml =
  @"%YAML 1.2
  ---
  !System.Drawing.SolidBrush
  Color: Red
  ...
  ";

SolidBrush b = null;
try {
  b = (SolidBrush)serializer.Deserialize(yaml)[0];
} catch(MissingMethodException) {
  // SolidBrush has no default constructor!
}

YamlNode.DefaultConfig.AddActivator<SolidBrush>(() => new SolidBrush(Color.Black));

// Now the serializer knows how to activate an instance of SolidBrush.
b = (SolidBrush)serializer.Deserialize(yaml)[0];

Assert.AreEqual(b.Color, Color.Red);

See Also

YamlConfig Class


AddRule(T) Method

[image]

YAML Serializer
YamlConfig..::.AddRule<(Of <(T>)>) Method
YamlConfig Class Example See Also Send Feedback
Add a custom tag resolution rule.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void AddRule<T>(
    string tag,
    string regex,
    Func<Match, T> decode,
    Func<T, string> encode
)
Visual Basic (Declaration)
Public Sub AddRule(Of T) ( _
    tag As String, _
    regex As String, _
    decode As Func(Of Match, T), _
    encode As Func(Of T, String) _
)
Visual C++
public:
generic<typename T>
void AddRule(
    String^ tag,
    String^ regex,
    Func<Match^, T>^ decode,
    Func<T, String^>^ encode
)

Parameters

tag
Type: System..::.String
Tag for the value.
regex
Type: System..::.String
Pattern to match the value.
decode
Type: System..::.Func <(Of <( Match, T>)>)
Method that decode value from Match data after matching by regex.
encode
Type: System..::.Func <(Of <(T, String >)>)
Method that encode value to String.

Type Parameters

T
Type of value.

Examples

CopyC#

  See Also
YamlConfig Class
System.Yaml Namespace

Send comments on this topic to
        Osamu TAKEUCHI


YamlMapping Class

[image]

YAML Serializer
YamlMapping Class
Members Example See Also Send Feedback
Represents a mapping node in a YAML document. Use IDictionary<YamlNode,YamlNode> interface to manipulate child key/value pairs.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public class YamlMapping : YamlComplexNode,
    IDictionary<YamlNode, YamlNode>, ICollection<KeyValuePair<YamlNode, YamlNode>>,
    IEnumerable<KeyValuePair<YamlNode, YamlNode>>, IEnumerable
Visual Basic (Declaration)
Public Class YamlMapping _
    Inherits YamlComplexNode _
    Implements IDictionary(Of YamlNode, YamlNode),  _
    ICollection(Of KeyValuePair(Of YamlNode, YamlNode)), IEnumerable(Of KeyValuePair(Of YamlNode, YamlNode)),  _
    IEnumerable
Visual C++
public ref class YamlMapping : public YamlComplexNode,
    IDictionary<YamlNode^, YamlNode^>, ICollection<KeyValuePair<YamlNode^, YamlNode^>>,
    IEnumerable<KeyValuePair<YamlNode^, YamlNode^>>, IEnumerable

Remarks

Child items can be accessed via IDictionary<YamlNode, YamlNode> interface. Note that mapping object can not contain multiple keys with same value.

Examples

CopyC#
// Create a mapping.
var map1 = new YamlMapping(
    // (key, value) pairs should be written sequential
    new YamlScalar("key1"), new YamlScalar("value1"),
    "key2", "value2" // implicitely converted to YamlScalar
    );

// Refer to the mapping.
Assert.AreEqual( map1[new Scalar("key1")], new YamlScalar("value1") );
Assert.AreEqual( map1["key1"], "value1" );

// Add an entry.
map1.Add( "key3", new YamlSequence( "value3a", "value3b" ) );

// Create another mapping.
var map2 = new YamlMapping(
    "key1", "value1",
    "key2", "value2",
    "key3", new YamlSequence( "value3a", "value3b" )
    );

// Mappings are equal when they have objects that are equal to each other.
Assert.IsTrue( map1.Equals( map2 ) );

Inheritance Hierarchy

System..::.Object
System.Yaml..::.YamlNode
System.Yaml..::.YamlComplexNode
System.Yaml..::.YamlMapping

See Also

YamlMapping Members


YamlMapping Members

[image] [image]

YAML Serializer
YamlMapping Members
YamlMapping Class Constructors Methods Properties Events See Also Send Feedback

The YamlMapping type exposes the following members.

Constructors

Name | Description
YamlMapping | Create a YamlMapping that contains nodes in it.

Methods

Name | Description
Add | Adds an element with the provided key and value.
Clear | Removes all entries from the YamlMapping.
Contains | Determines whether the YamlMapping contains a specific value.
ContainsKey | Determines whether the YamlMapping contains an element with the specified key.
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetEnumerator | Returns an enumerator that iterates through the YamlMapping.
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Calculate hash code from Tag property and all child nodes. The result is cached. (Inherited from YamlComplexNode.)
GetHashCodeCoreSub | Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree. (Overrides YamlComplexNode..::.GetHashCodeCoreSub(Int32, Dictionary<(Of <(YamlNode, Int32>)>)).)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Inherited from YamlNode.)
Remove | Removes the element with the specified key from the YamlMapping.
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.
TryGetValue | Gets the value associated with the specified key.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Count | Returns the number of entries in a YamlMapping.
Item | Gets or sets the element with the specified key.
Keys | Gets an ICollection<YamlNode> containing the keys of the YamlMapping.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)
Values | Gets an ICollection<YamlNode> containing the values of the YamlMapping.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlMapping Class


YamlMapping Constructor

[image]

YAML Serializer
YamlMapping Constructor
YamlMapping Class Example See Also Send Feedback
Create a YamlMapping that contains nodes in it.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlMapping(
    params YamlNode[] nodes
)
Visual Basic (Declaration)
Public Sub New ( _
    ParamArray nodes As YamlNode() _
)
Visual C++
public:
YamlMapping(
    ... array<YamlNode^>^ nodes
)

Parameters

nodes
Type: array< System.Yaml..::.YamlNode >[]()[]
(key, value) pairs are written sequential.

Examples

CopyC#
// Create a mapping.
var map1 = new YamlMapping(
    // (key, value) pairs should be written sequential
    new YamlScalar("key1"), new YamlScalar("value1"),
    new YamlScalar("key2"), new YamlScalar("value2")
    );

Exceptions

Exception | Condition
System..::.ArgumentException | Even number of arguments are expected.

See Also

YamlMapping Class


YamlMapping Methods

[image] [image]

YAML Serializer
YamlMapping Methods
YamlMapping Class See Also Send Feedback

The YamlMapping type exposes the following members.

Methods

Name | Description
Add | Adds an element with the provided key and value.
Clear | Removes all entries from the YamlMapping.
Contains | Determines whether the YamlMapping contains a specific value.
ContainsKey | Determines whether the YamlMapping contains an element with the specified key.
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetEnumerator | Returns an enumerator that iterates through the YamlMapping.
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Calculate hash code from Tag property and all child nodes. The result is cached. (Inherited from YamlComplexNode.)
GetHashCodeCoreSub | Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree. (Overrides YamlComplexNode..::.GetHashCodeCoreSub(Int32, Dictionary<(Of <(YamlNode, Int32>)>)).)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Inherited from YamlNode.)
Remove | Removes the element with the specified key from the YamlMapping.
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.
TryGetValue | Gets the value associated with the specified key.

See Also

YamlMapping Class


Add Method

[image]

YAML Serializer
YamlMapping..::.Add Method
YamlMapping Class See Also Send Feedback
Adds an element with the provided key and value.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Add(
    YamlNode key,
    YamlNode value
)
Visual Basic (Declaration)
Public Sub Add ( _
    key As YamlNode, _
    value As YamlNode _
)
Visual C++
public:
virtual void Add(
    YamlNode^ key,
    YamlNode^ value
) sealed

Parameters

key
Type: System.Yaml..::.YamlNode
The node to use as the key of the element to add.
value
Type: System.Yaml..::.YamlNode
The node to use as the value of the element to add.

Implements

IDictionary<(Of <(TKey, TValue>)>)..::.Add(TKey, TValue)

Exceptions

Exception | Condition
System..::.ArgumentNullException | key or value is a null reference.
System..::.ArgumentException | An element with the same key already exists.

See Also

YamlMapping Class


Clear Method

[image]

YAML Serializer
YamlMapping..::.Clear Method
YamlMapping Class See Also Send Feedback
Removes all entries from the YamlMapping.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Clear()
Visual Basic (Declaration)
Public Sub Clear
Visual C++
public:
virtual void Clear() sealed

Implements

ICollection<(Of <(T>)>)..::.Clear()()()

See Also

YamlMapping Class


Contains Method

[image]

YAML Serializer
YamlMapping..::.Contains Method
YamlMapping Class See Also Send Feedback
Determines whether the YamlMapping contains a specific value.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool Contains(
    KeyValuePair<YamlNode, YamlNode> item
)
Visual Basic (Declaration)
Public Function Contains ( _
    item As KeyValuePair(Of YamlNode, YamlNode) _
) As Boolean
Visual C++
public:
virtual bool Contains(
    KeyValuePair<YamlNode^, YamlNode^> item
) sealed

Parameters

item
Type: System.Collections.Generic..::.KeyValuePair <(Of <( YamlNode, YamlNode >)>)
The object to locate in the YamlMapping.

Return Value

true if item is found in the YamlMapping otherwise, false.

Implements

ICollection<(Of <(T>)>)..::.Contains(T)

See Also

YamlMapping Class


ContainsKey Method

[image]

YAML Serializer
YamlMapping..::.ContainsKey Method
YamlMapping Class See Also Send Feedback
Determines whether the YamlMapping contains an element with the specified key.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool ContainsKey(
    YamlNode key
)
Visual Basic (Declaration)
Public Function ContainsKey ( _
    key As YamlNode _
) As Boolean
Visual C++
public:
virtual bool ContainsKey(
    YamlNode^ key
) sealed

Parameters

key
Type: System.Yaml..::.YamlNode
The key to locate in the YamlMapping.

Return Value

true if the YamlMapping contains an element with the key that is equal to the specified value; otherwise, false.

Implements

IDictionary<(Of <(TKey, TValue>)>)..::.ContainsKey(TKey)

Exceptions

Exception | Condition
System..::.ArgumentNullException | key is a null reference

See Also

YamlMapping Class


GetEnumerator Method

[image]

YAML Serializer
YamlMapping..::.GetEnumerator Method
YamlMapping Class See Also Send Feedback
Returns an enumerator that iterates through the YamlMapping.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public IEnumerator<KeyValuePair<YamlNode, YamlNode>> GetEnumerator()
Visual Basic (Declaration)
Public Function GetEnumerator As IEnumerator(Of KeyValuePair(Of YamlNode, YamlNode))
Visual C++
public:
virtual IEnumerator<KeyValuePair<YamlNode^, YamlNode^>>^ GetEnumerator() sealed

Return Value

An enumerator that iterates through the YamlMapping.

Implements

IEnumerable<(Of <(T>)>)..::.GetEnumerator()()()

See Also

YamlMapping Class


GetHashCodeCoreSub Method

[image]

YAML Serializer
YamlMapping..::.GetHashCodeCoreSub Method
YamlMapping Class See Also Send Feedback
Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected override int GetHashCodeCoreSub(
    int path,
    Dictionary<YamlNode, int> dict
)
Visual Basic (Declaration)
Protected Overrides Function GetHashCodeCoreSub ( _
    path As Integer, _
    dict As Dictionary(Of YamlNode, Integer) _
) As Integer
Visual C++
protected:
virtual int GetHashCodeCoreSub(
    int path,
    Dictionary<YamlNode^, int>^ dict
) override

Parameters

path
Type: System..::.Int32
The cache code for the path where this node was found.
dict
Type: System.Collections.Generic..::.Dictionary <(Of <( YamlNode, Int32 >)>)
Repository of the nodes that already appeared in the node tree. Sub hash code for the nodes can be refered to from this dictionary.

Return Value

[Missing <returns> documentation for "M:System.Yaml.YamlMapping.GetHashCodeCoreSub(System.Int32,System.Collections.Generic.Dictionary{System.Yaml.YamlNode,System.Int32})"]

See Also

YamlMapping Class


Remove Method

[image]

YAML Serializer
YamlMapping..::.Remove Method
YamlMapping Class See Also Send Feedback
Removes the element with the specified key from the YamlMapping.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool Remove(
    YamlNode key
)
Visual Basic (Declaration)
Public Function Remove ( _
    key As YamlNode _
) As Boolean
Visual C++
public:
virtual bool Remove(
    YamlNode^ key
) sealed

Parameters

key
Type: System.Yaml..::.YamlNode
The key of the element to remove.

Return Value

true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original YamlMapping.

Implements

IDictionary<(Of <(TKey, TValue>)>)..::.Remove(TKey)

See Also

YamlMapping Class


ToYaml Method

[image] [image]

YAML Serializer
YamlMapping..::.ToYaml Method
YamlMapping Class See Also Send Feedback

Overload List

Name | Description
ToYaml()()() | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)
ToYaml(YamlConfig) | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream, YamlConfig) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter, YamlConfig) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)

See Also

YamlMapping Class
YamlMapping Members


ToYamlFile Method

[image] [image]

YAML Serializer
YamlMapping..::.ToYamlFile Method
YamlMapping Class See Also Send Feedback

Overload List

Name | Description
ToYamlFile(String) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)
ToYamlFile(String, YamlConfig) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)

See Also

YamlMapping Class
YamlMapping Members


TryGetValue Method

[image]

YAML Serializer
YamlMapping..::.TryGetValue Method
YamlMapping Class See Also Send Feedback
Gets the value associated with the specified key.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool TryGetValue(
    YamlNode key,
    out YamlNode value
)
Visual Basic (Declaration)
Public Function TryGetValue ( _
    key As YamlNode, _
    <OutAttribute> ByRef value As YamlNode _
) As Boolean
Visual C++
public:
virtual bool TryGetValue(
    YamlNode^ key,
    [OutAttribute] YamlNode^% value
) sealed

Parameters

key
Type: System.Yaml..::.YamlNode
The key whose value to get.
value
Type: System.Yaml..::.YamlNode %
When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Return Value

true if the object that implements YamlMapping contains an element with the specified key; otherwise, false.

Implements

IDictionary<(Of <(TKey, TValue>)>)..::.TryGetValue(TKey, TValue%)

See Also

YamlMapping Class


YamlMapping Properties

[image] [image]

YAML Serializer
YamlMapping Properties
YamlMapping Class See Also Send Feedback

The YamlMapping type exposes the following members.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Count | Returns the number of entries in a YamlMapping.
Item | Gets or sets the element with the specified key.
Keys | Gets an ICollection<YamlNode> containing the keys of the YamlMapping.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)
Values | Gets an ICollection<YamlNode> containing the values of the YamlMapping.

See Also

YamlMapping Class


Count Property

[image]

YAML Serializer
YamlMapping..::.Count Property
YamlMapping Class See Also Send Feedback
Returns the number of entries in a YamlMapping.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public int Count { get; }
Visual Basic (Declaration)
Public ReadOnly Property Count As Integer
Visual C++
public:
virtual property int Count {
    int get () sealed;
}

Implements

ICollection<(Of <(T>)>)..::.Count

See Also

YamlMapping Class


Item Property

[image]

YAML Serializer
YamlMapping..::.Item Property
YamlMapping Class See Also Send Feedback
Gets or sets the element with the specified key.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlNode this[
    YamlNode key
] { get; set; }
Visual Basic (Declaration)
Public Default Property Item ( _
    key As YamlNode _
) As YamlNode
Visual C++
public:
virtual property YamlNode^ default[YamlNode^ key] {
    YamlNode^ get (YamlNode^ key) sealed;
    void set (YamlNode^ key, YamlNode^ value) sealed;
}

Parameters

key
Type: System.Yaml..::.YamlNode
The key of the element to get or set.

Return Value

The element with the specified key.

Implements

IDictionary<(Of <(TKey, TValue>)>)..::.Item[([(TKey])])

Exceptions

Exception | Condition
System..::.ArgumentNullException | key is a null reference
System.Collections.Generic..::.KeyNotFoundException | The property is retrieved and key is not found.

See Also

YamlMapping Class


Keys Property

[image]

YAML Serializer
YamlMapping..::.Keys Property
YamlMapping Class See Also Send Feedback
Gets an ICollection<YamlNode> containing the keys of the YamlMapping.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public ICollection<YamlNode> Keys { get; }
Visual Basic (Declaration)
Public ReadOnly Property Keys As ICollection(Of YamlNode)
Visual C++
public:
virtual property ICollection<YamlNode^>^ Keys {
    ICollection<YamlNode^>^ get () sealed;
}

Implements

IDictionary<(Of <(TKey, TValue>)>)..::.Keys

See Also

YamlMapping Class


Values Property

[image]

YAML Serializer
YamlMapping..::.Values Property
YamlMapping Class See Also Send Feedback
Gets an ICollection<YamlNode> containing the values of the YamlMapping.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public ICollection<YamlNode> Values { get; }
Visual Basic (Declaration)
Public ReadOnly Property Values As ICollection(Of YamlNode)
Visual C++
public:
virtual property ICollection<YamlNode^>^ Values {
    ICollection<YamlNode^>^ get () sealed;
}

Implements

IDictionary<(Of <(TKey, TValue>)>)..::.Values

See Also

YamlMapping Class


YamlMapping Events

[image] [image]

YAML Serializer
YamlMapping Events
YamlMapping Class See Also Send Feedback

The YamlMapping type exposes the following members.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlMapping Class


YamlNode Class
Members Example See Also Send Feedback

Abstract base class of YAML data nodes.

See YamlScalar, YamlSequence and YamlMapping for actual data classes.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public abstract class YamlNode
Visual Basic (Declaration)
Public MustInherit Class YamlNode
Visual C++
public ref class YamlNode abstract

Remarks

YAML data model

See http://yaml.org/ for the official definition of Information Models of YAML.

YAML data structure is defined as follows. Note that this does not represents the text syntax of YAML text but does logical data structure.

yaml-stream ::= yaml-document*
yaml-document ::= yaml-directive* yaml-node
yaml-directive ::= YAML-directive | TAG-directive | user-defined-directive
yaml-node ::= yaml-scalar | yaml-sequence | yaml-mapping
yaml-scalar ::= yaml-tag yaml-value
yaml-sequence ::= yaml-tag yaml-node*
yaml-mapping ::= yaml-tag ( yaml-node yaml-node )*
yaml-tag ::= yaml-global-tag yaml-local-tag
yaml-global-tag ::= "tag:" taggingEntity ":" specific [ "#" fragment ]
yaml-local-tag ::= "!" yaml-local-tag-name

Namely,

A YAML stream consists of zero or more YAML documents.
A YAML documents have zero or more YAML directives and a root YAML node.
A YAML directive is either YAML-directive, TAG-directive or user-defined-directive.
A YAML node is either YAML scalar, YAML sequence or YAML mapping.
A YAML scalar consists of a YAML tag and a scalar value.
A YAML sequence consists of a YAML tag and zero or more child YAML nodes.
A YAML mapping cosists of a YAML tag and zero or more key/value pairs of YAML nodes.
A YAML tag is either a YAML global tag or a YAML local tag.
A YAML global tag starts with "tag:" and described in the "tag:" URI scheme defined in RFC4151.
A YAML local tag starts with "!" with a YAML local tag name

CopyC#
// Construct YAML node tree
YamlNode node =
    new YamlSequence(                           // !!seq node
        new YamlScalar("abc"),                  // !!str node
        new YamlScalar("!!int", "123"),         // !!int node
        new YamlScalar("!!float", "1.23"),      // !!float node
        new YamlSequence(                       // nesting !!seq node
            new YamlScalar("def"),
            new YamlScalar("ghi")
        ),
        new YamlMapping(                        // !!map node
            new YamlScalar("key1"), new YamlScalar("value1"),
            new YamlScalar("key2"), new YamlScalar("value2"),
            new YamlScalar("key3"), new YamlMapping(    // nesting !!map node
                new YamlScalar("value3key1"), new YamlScalar("value3value1")
            ),
            new YamlScalar("key4"), new YamlScalar("value4")
        )
    );

// Convert it to YAML stream
string yaml = node.ToYaml();

// %YAML 1.2
// ---
// - abc
// - 123
// - 1.23
// - - def
//   - ghi
// - key1: value1
//   key2: value2
//   key3:
//     value3key1: value3value1
//   key4: value4
// ...

// Load the YAML node from the YAML stream.
// Note that a YAML stream can contain several YAML documents each of which
// contains a root YAML node.
YamlNode[] nodes = YamlNode.FromYaml(yaml);

// The only one node in the stream is the one we have presented above.
Assert.AreEqual(1, nodes.Length);
YamlNode resotred = nodes[0];

// Check if they are equal to each other.
Assert.AreEquel(node, restored);

// Extract sub nodes.
var seq = (YamlSequence)restored;
var map = (YamlMapping)seq[4];
var map2 = (YamlMapping)map[new YamlScalar("key3")];

// Modify the restored node tree
map2[new YamlScalar("value3key1")] = new YamlScalar("value3value1 modified");

// Now they are not equal to each other.
Assert.AreNotEquel(node, restored);

YamlNode class

YamlNode is an abstract class that represents a YAML node.

In reality, a YamlNode is either YamlScalar, YamlSequence or YamlMapping.

All YamlNode has Tag property that denotes the actual data type represented in the YAML node.

Default Tag value for YamlScalar, YamlSequence or YamlMapping are "tag:yaml.org,2002:str", "tag:yaml.org,2002:seq", "tag:yaml.org,2002:map".

Global tags that starts with "tag:yaml.org,2002:" ( = YamlNode.DefaultTagPrefix) are defined in the YAML tag repository at http://yaml.org/type/. In this library, such a tags can be also represented in a short form that starts with "!!", like "!!str", "!!seq" and "!!map". Tags in the formal style and the shorthand form can be converted to each other by the static methods of ExpandTag(String) and ShorthandTag(String). In addition to these three basic tags, this library uses "!!null", "!!bool", "!!int", "!!float" and "!!timestamp" tags, by default.

YamlNodes can be read from a YAML stream with FromYaml(String), FromYaml(Stream), FromYaml(TextReader) and FromYamlFile(String) static methods. Since a YAML stream generally consist of multiple YAML documents, each of which has a root YAML node, these methods return an array of YamlNode that is contained in the stream.

YamlNodes can be written to a YAML stream with ToYaml()()(), ToYaml(Stream), ToYaml(TextWriter) and ToYamlFile(String).

The way of serialization can be configured in some aspects. The custom settings are specified by an instance of YamlConfig class. The serialization methods introduced above has overloaded styles that accepts YamlConfig instance to customize serialization. It is also possible to change the default serialization method by modifying YamlNode.DefaultConfig static property.

A YamlScalar has Value property, which holds the string expression of the node value.

A YamlSequence implements IList<YamlNode> interface to access the child nodes.

YamlMapping implements IDictionary<YamlNode,YamlNode> interface to access the key/value pairs under the node.

Implicit conversion from C# native object to YamlScalar

Implicit cast operators from String, Boolean, Int32, Double and DateTime to YamlNode is defined. Thus, anytime YamlNode is required in C# source, naked scalar value can be written. Namely, methods of YamlSequence and YamlMapping accept such C# native types as arguments in addition to YamlNode types.

CopyC#
var map = new YamlMapping();
map["Time"] = DateTime.Now;                 // implicitly converted to YamlScalar
Assert.IsTrue(map.ContainsKey(new YamlScalar("Time")));
Assert.IsTrue(map.ContainsKey("Time"));     // implicitly converted to YamlScalar

Equality of YamlNodes

Equality of YamlNodes are evaluated on the content base. Different YamlNode objects that have the same content are evaluated to be equal. Use Equals(Object) method for equality evaluation.

In detail, two YamlNodes are logically equal to each other when the YamlNode and its child nodes have the same contents (Tag and Value) and their node graph topology is exactly same.

CopyC#
YamlNode a1 = "a";  // implicit conversion
YamlNode a2 = "a";  // implicit conversion
YamlNode a3 = new YamlNode("!char", "a");
YamlNode b  = "b";  // implicit conversion

Assert.IsTrue(a1 != a2);        // different objects
Assert.IsTrue(a1.Equals(a2));   // different objects having same content

Assert.IsFalse(a1.Equals(a3));  // Tag is different
Assert.IsFalse(a1.Equals(b));   // Value is different

var s1 = new YamlMapping(a1, new YamlSequence(a1, a2));
var s2 = new YamlMapping(a1, new YamlSequence(a2, a1));
var s3 = new YamlMapping(a2, new YamlSequence(a1, a2));

Assert.IsFalse(s1.Equals(s2)); // node graph topology is different
Assert.IsFalse(s1.Equals(s3)); // node graph topology is different
Assert.IsTrue(s2.Equals(s3));  // different objects having same content and node graph topology

Examples

Example 2.27 in YAML 1.2 specification
CopyC#
// %YAML 1.2
// ---
// !<tag:clarkevans.com,2002:invoice>
// invoice: 34843
// date   : 2001-01-23
// bill-to: &id001
//     given  : Chris
//     family : Dumars
//     address:
//         lines: |
//             458 Walkman Dr.
//             Suite #292
//         city    : Royal Oak
//         state   : MI
//         postal  : 48046
// ship-to: *id001
// product:
//     - sku         : BL394D
//       quantity    : 4
//       description : Basketball
//       price       : 450.00
//     - sku         : BL4438H
//       quantity    : 1
//       description : Super Hoop
//       price       : 2392.00
// tax  : 251.42
// total: 4443.52
// comments:
//     Late afternoon is best.
//     Backup contact is Nancy
//     Billsmer @ 338-4338.
// ...

var invoice = new YamlMapping(
    "invoice", 34843,
    "date", new DateTime(2001, 01, 23),
    "bill-to", new YamlMapping(
        "given", "Chris",
        "family", "Dumars",
        "address", new YamlMapping(
            "lines", "458 Walkman Dr.\nSuite #292\n",
            "city", "Royal Oak",
            "state", "MI",
            "postal", 48046
            )
        ),
    "product", new YamlSequence(
        new YamlMapping(
            "sku",         "BL394D",
            "quantity",    4,
            "description", "Basketball",
            "price",       450.00
            ),
        new YamlMapping(
            "sku",         "BL4438H",
            "quantity",    1,
            "description", "Super Hoop",
            "price",       2392.00
            )
        ),
    "tax", 251.42,
    "total", 4443.52,
    "comments", "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338."
    );
invoice["ship-to"] = invoice["bill-to"];
invoice.Tag = "tag:clarkevans.com,2002:invoice";

invoice.ToYamlFile("invoice.yaml");
// %YAML 1.2
// ---
// !<tag:clarkevans.com,2002:invoice>
// invoice: 34843
// date: 2001-01-23
// bill-to: &A
//   given: Chris
//   family: Dumars
//   address:
//     lines: "458 Walkman Dr.\n\
//       Suite #292\n"
//     city: Royal Oak
//     state: MI
//     postal: 48046
// product:
//   - sku: BL394D
//     quantity: 4
//     description: Basketball
//     price: !!float 450
//   - sku: BL4438H
//     quantity: 1
//     description: Super Hoop
//     price: !!float 2392
// tax: 251.42
// total: 4443.52
// comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
// ship-to: *A
// ...

Inheritance Hierarchy

System..::.Object
System.Yaml..::.YamlNode
System.Yaml..::.YamlComplexNode
System.Yaml..::.YamlScalar

See Also

YamlNode Members


YamlNode Members

[image] [image]

YAML Serializer
YamlNode Members
YamlNode Class Constructors Methods Properties Events See Also Send Feedback

The YamlNode type exposes the following members.

Constructors

Name | Description
YamlNode | Initialize a node.

Methods

Name | Description
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Overrides Object..::.Equals(Object).)
ExpandTag | Convert shorthand tag starting with "!!" to the formal style that starts with "tag:yaml.org,2002:".
Finalize | (Inherited from Object.)
FromYaml | Overloaded.
FromYamlFile | Overloaded.
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Overrides Object..::.GetHashCode()()().)
GetHashCodeCore | Return the hash code. The returned value will be cached until OnChanged()()() is called.
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed.
ShorthandTag | Overloaded.
ToString | Returns a String that represents the current Object. (Overrides Object..::.ToString()()().)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

Operators

Name | Description
Implicit | Overloaded.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time.
DefaultConfig | Gets or sets the default configuration to customize serialization of YamlNode.
DefaultTagPrefix | Gets YAML's default tag prefix.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time.
Tag | YAML Tag for this node, which represents the type of node's value.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed.

See Also

YamlNode Class


YamlNode Constructor

[image]

YAML Serializer
YamlNode Constructor
YamlNode Class See Also Send Feedback
Initialize a node.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlNode()
Visual Basic (Declaration)
Public Sub New
Visual C++
public:
YamlNode()

See Also

YamlNode Class


YamlNode Methods

[image] [image]

YAML Serializer
YamlNode Methods
YamlNode Class See Also Send Feedback

The YamlNode type exposes the following members.

Methods

Name | Description
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Overrides Object..::.Equals(Object).)
ExpandTag | Convert shorthand tag starting with "!!" to the formal style that starts with "tag:yaml.org,2002:".
Finalize | (Inherited from Object.)
FromYaml | Overloaded.
FromYamlFile | Overloaded.
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Overrides Object..::.GetHashCode()()().)
GetHashCodeCore | Return the hash code. The returned value will be cached until OnChanged()()() is called.
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed.
ShorthandTag | Overloaded.
ToString | Returns a String that represents the current Object. (Overrides Object..::.ToString()()().)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

Operators

Name | Description
Implicit | Overloaded.

See Also

YamlNode Class


Equals Method

[image]

YAML Serializer
YamlNode..::.Equals Method
YamlNode Class Example See Also Send Feedback
Returns true if obj is of same type as the YamlNode and its content is also logically same.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public override bool Equals(
    Object obj
)
Visual Basic (Declaration)
Public Overrides Function Equals ( _
    obj As Object _
) As Boolean
Visual C++
public:
virtual bool Equals(
    Object^ obj
) override

Parameters

obj
Type: System..::.Object
Object to be compared.

Return Value

True if the YamlNode logically equals to the obj; otherwise false.

Remarks

Two YamlNode's are logically equal when the YamlNode and its child nodes have the same contents (Tag and Value) and their node graph topology is exactly same as the other.

Examples

CopyC#
var a1 = new YamlNode("a");
var a2 = new YamlNode("a");
var a3 = new YamlNode("!char", "a");
var b  = new YamlNode("b");

Assert.IsTrue(a1 != a2);        // different objects
Assert.IsTrue(a1.Equals(a2));   // different objects having same content

Assert.IsFalse(a1.Equals(a3));  // Tag is different
Assert.IsFalse(a1.Equals(b));   // Value is different

var s1 = new YamlMapping(a1, new YamlSequence(a1, a2));
var s2 = new YamlMapping(a1, new YamlSequence(a2, a1));
var s3 = new YamlMapping(a2, new YamlSequence(a1, a2));

Assert.IsFalse(s1.Equals(s2)); // node graph topology is different
Assert.IsFalse(s1.Equals(s3)); // node graph topology is different
Assert.IsTrue(s2.Equals(s3));  // different objects having same content and node graph topology

See Also

YamlNode Class


ExpandTag Method

[image]

YAML Serializer
YamlNode..::.ExpandTag Method
YamlNode Class Example See Also Send Feedback
Convert shorthand tag starting with "!!" to the formal style that starts with "tag:yaml.org,2002:".

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static string ExpandTag(
    string tag
)
Visual Basic (Declaration)
Public Shared Function ExpandTag ( _
    tag As String _
) As String
Visual C++
public:
static String^ ExpandTag(
    String^ tag
)

Parameters

tag
Type: System..::.String
Tag in the shorthand style.

Return Value

Tag in formal style.

Remarks

When tag starts with "!!", it is converted into formal style. Otherwise, tag is returned as is.

Examples

CopyC#
var tag = YamlNode.DefaultTagPrefix + "int";    // -> "tag:yaml.org,2002:int"
tag = YamlNode.ShorthandTag(tag);               // -> "!!int"
tag = YamlNode.ExpandTag(tag);                  // -> "tag:yaml.org,2002:int"

See Also

YamlNode Class


FromYaml Method

[image] [image]

YAML Serializer
YamlNode..::.FromYaml Method
YamlNode Class See Also Send Feedback

Overload List

Name | Description
FromYaml(Stream) | Convert YAML text yaml to a list of YamlNode.
FromYaml(TextReader) | Convert YAML text yaml to a list of YamlNode.
FromYaml(String) | Convert YAML text yaml to a list of YamlNode.
FromYaml(Stream, YamlConfig) | Convert YAML text yaml to a list of YamlNode.
FromYaml(TextReader, YamlConfig) | Convert YAML text yaml to a list of YamlNode.
FromYaml(String, YamlConfig) | Convert YAML text yaml to a list of YamlNode.

See Also

YamlNode Class
YamlNode Members


FromYaml Method (Stream)

[image]

YAML Serializer
YamlNode..::.FromYaml Method (Stream)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYaml(
    Stream s
)
Visual Basic (Declaration)
Public Shared Function FromYaml ( _
    s As Stream _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYaml(
    Stream^ s
)

Parameters

s
Type: System.IO..::.Stream
Stream from which YAML document is read.

Return Value

YAML nodes

See Also

YamlNode Class
FromYaml Overload


FromYaml Method (TextReader)

[image]

YAML Serializer
YamlNode..::.FromYaml Method (TextReader)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYaml(
    TextReader tr
)
Visual Basic (Declaration)
Public Shared Function FromYaml ( _
    tr As TextReader _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYaml(
    TextReader^ tr
)

Parameters

tr
Type: System.IO..::.TextReader
TextReader from which YAML document is read.

Return Value

YAML nodes

See Also

YamlNode Class
FromYaml Overload


FromYaml Method (String)

[image]

YAML Serializer
YamlNode..::.FromYaml Method (String)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYaml(
    string yaml
)
Visual Basic (Declaration)
Public Shared Function FromYaml ( _
    yaml As String _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYaml(
    String^ yaml
)

Parameters

yaml
Type: System..::.String
YAML text

Return Value

YAML nodes

See Also

YamlNode Class
FromYaml Overload


FromYaml Method (Stream, YamlConfig)

[image]

YAML Serializer
YamlNode..::.FromYaml Method (Stream, YamlConfig)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYaml(
    Stream s,
    YamlConfig config
)
Visual Basic (Declaration)
Public Shared Function FromYaml ( _
    s As Stream, _
    config As YamlConfig _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYaml(
    Stream^ s,
    YamlConfig^ config
)

Parameters

s
Type: System.IO..::.Stream
Stream from which YAML document is read.
config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

Return Value

YAML nodes

See Also

YamlNode Class
FromYaml Overload


FromYaml Method (TextReader, YamlConfig)

[image]

YAML Serializer
YamlNode..::.FromYaml Method (TextReader, YamlConfig)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYaml(
    TextReader tr,
    YamlConfig config
)
Visual Basic (Declaration)
Public Shared Function FromYaml ( _
    tr As TextReader, _
    config As YamlConfig _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYaml(
    TextReader^ tr,
    YamlConfig^ config
)

Parameters

tr
Type: System.IO..::.TextReader
TextReader from which YAML document is read.
config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

Return Value

YAML nodes

See Also

YamlNode Class
FromYaml Overload


FromYaml Method (String, YamlConfig)

[image]

YAML Serializer
YamlNode..::.FromYaml Method (String, YamlConfig)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYaml(
    string yaml,
    YamlConfig config
)
Visual Basic (Declaration)
Public Shared Function FromYaml ( _
    yaml As String, _
    config As YamlConfig _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYaml(
    String^ yaml,
    YamlConfig^ config
)

Parameters

yaml
Type: System..::.String
YAML text
config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

Return Value

YAML nodes

See Also

YamlNode Class
FromYaml Overload


FromYamlFile Method

[image] [image]

YAML Serializer
YamlNode..::.FromYamlFile Method
YamlNode Class See Also Send Feedback

Overload List

Name | Description
FromYamlFile(String) | Convert YAML text yaml to a list of YamlNode.
FromYamlFile(String, YamlConfig) | Convert YAML text yaml to a list of YamlNode.

See Also

YamlNode Class
YamlNode Members


FromYamlFile Method (String)

[image]

YAML Serializer
YamlNode..::.FromYamlFile Method (String)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYamlFile(
    string FileName
)
Visual Basic (Declaration)
Public Shared Function FromYamlFile ( _
    FileName As String _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYamlFile(
    String^ FileName
)

Parameters

FileName
Type: System..::.String
YAML File Name

Return Value

YAML nodes

See Also

YamlNode Class
FromYamlFile Overload


FromYamlFile Method (String, YamlConfig)

[image]

YAML Serializer
YamlNode..::.FromYamlFile Method (String, YamlConfig)
YamlNode Class See Also Send Feedback
Convert YAML text yaml to a list of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlNode[] FromYamlFile(
    string FileName,
    YamlConfig config
)
Visual Basic (Declaration)
Public Shared Function FromYamlFile ( _
    FileName As String, _
    config As YamlConfig _
) As YamlNode()
Visual C++
public:
static array<YamlNode^>^ FromYamlFile(
    String^ FileName,
    YamlConfig^ config
)

Parameters

FileName
Type: System..::.String
YAML File Name
config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

Return Value

YAML nodes

See Also

YamlNode Class
FromYamlFile Overload


GetHashCode Method

[image]

YAML Serializer
YamlNode..::.GetHashCode Method
YamlNode Class See Also Send Feedback
Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public override int GetHashCode()
Visual Basic (Declaration)
Public Overrides Function GetHashCode As Integer
Visual C++
public:
virtual int GetHashCode() override

Return Value

Hash code

See Also

YamlNode Class


GetHashCodeCore Method

[image]

YAML Serializer
YamlNode..::.GetHashCodeCore Method
YamlNode Class See Also Send Feedback
Return the hash code. The returned value will be cached until OnChanged()()() is called.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected abstract int GetHashCodeCore()
Visual Basic (Declaration)
Protected MustOverride Function GetHashCodeCore As Integer
Visual C++
protected:
virtual int GetHashCodeCore() abstract

Return Value

Hash code

See Also

YamlNode Class


Implicit Method

[image] [image]

YAML Serializer
YamlNode..::.Implicit Method
YamlNode Class See Also Send Feedback

Overload List

Name | Description
Implicit(Boolean) | Implicit conversion from string to YamlScalar.
Implicit(DateTime) | Implicit conversion from DateTime to YamlScalar.
Implicit(Double) | Implicit conversion from string to YamlScalar.
Implicit(Int32) | Implicit conversion from string to YamlScalar.
Implicit(String) | Implicit conversion from string to YamlScalar.

See Also

YamlNode Class
YamlNode Members


Implicit Operator

[image]

YAML Serializer
YamlNode..::.Implicit Operator
YamlNode Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlNode (
    bool value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As Boolean _
) As YamlNode
Visual C++
static implicit operator YamlNode^ (
    bool value
)

Parameters

value
Type: System..::.Boolean
Value to be converted.

Return Value

Conversion result.

See Also

YamlNode Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlNode..::.Implicit Operator
YamlNode Class See Also Send Feedback
Implicit conversion from DateTime to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlNode (
    DateTime value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As DateTime _
) As YamlNode
Visual C++
static implicit operator YamlNode^ (
    DateTime value
)

Parameters

value
Type: System..::.DateTime
Value to be converted.

Return Value

Conversion result.

See Also

YamlNode Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlNode..::.Implicit Operator
YamlNode Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlNode (
    double value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As Double _
) As YamlNode
Visual C++
static implicit operator YamlNode^ (
    double value
)

Parameters

value
Type: System..::.Double
Value to be converted.

Return Value

Conversion result.

See Also

YamlNode Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlNode..::.Implicit Operator
YamlNode Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlNode (
    int value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As Integer _
) As YamlNode
Visual C++
static implicit operator YamlNode^ (
    int value
)

Parameters

value
Type: System..::.Int32
Value to be converted.

Return Value

Conversion result.

See Also

YamlNode Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlNode..::.Implicit Operator
YamlNode Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlNode (
    string value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As String _
) As YamlNode
Visual C++
static implicit operator YamlNode^ (
    String^ value
)

Parameters

value
Type: System..::.String
Value to be converted.

Return Value

Conversion result.

See Also

YamlNode Class
Implicit Overload


OnChanged Method

[image]

YAML Serializer
YamlNode..::.OnChanged Method
YamlNode Class See Also Send Feedback
Call this function when the content of the node is changed.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected virtual void OnChanged()
Visual Basic (Declaration)
Protected Overridable Sub OnChanged
Visual C++
protected:
virtual void OnChanged()

See Also

YamlNode Class


ShorthandTag Method

[image] [image]

YAML Serializer
YamlNode..::.ShorthandTag Method
YamlNode Class See Also Send Feedback

Overload List

Name | Description
ShorthandTag()()() | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style.
ShorthandTag(String) | Convert a formal style tag that starts with "tag:yaml.org,2002:" to the shorthand style that starts with "!!".

See Also

YamlNode Class
YamlNode Members


ShorthandTag Method

[image]

YAML Serializer
YamlNode..::.ShorthandTag Method
YamlNode Class See Also Send Feedback
YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string ShorthandTag()
Visual Basic (Declaration)
Public Function ShorthandTag As String
Visual C++
public:
String^ ShorthandTag()

Return Value

[Missing <returns> documentation for "M:System.Yaml.YamlNode.ShorthandTag"]

See Also

YamlNode Class
ShorthandTag Overload


ShorthandTag Method (String)

[image]

YAML Serializer
YamlNode..::.ShorthandTag Method (String)
YamlNode Class Example See Also Send Feedback
Convert a formal style tag that starts with "tag:yaml.org,2002:" to the shorthand style that starts with "!!".

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static string ShorthandTag(
    string tag
)
Visual Basic (Declaration)
Public Shared Function ShorthandTag ( _
    tag As String _
) As String
Visual C++
public:
static String^ ShorthandTag(
    String^ tag
)

Parameters

tag
Type: System..::.String
Tag in formal style.

Return Value

Tag in compact style.

Remarks

When tag contains YAML standard types, it is converted into !!xxx style. Otherwise, tag is returned as is.

Examples

CopyC#
var tag = YamlNode.DefaultTagPrefix + "int";    // -> "tag:yaml.org,2002:int"
tag = YamlNode.ShorthandTag(tag);               // -> "!!int"
tag = YamlNode.ExpandTag(tag);                  // -> "tag:yaml.org,2002:int"

See Also

YamlNode Class
ShorthandTag Overload


ToString Method

[image]

YAML Serializer
YamlNode..::.ToString Method
YamlNode Class See Also Send Feedback
Returns a String that represents the current Object.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public override string ToString()
Visual Basic (Declaration)
Public Overrides Function ToString As String
Visual C++
public:
virtual String^ ToString() override

Return Value

A String that represents the current Object

See Also

YamlNode Class


ToYaml Method

[image] [image]

YAML Serializer
YamlNode..::.ToYaml Method
YamlNode Class See Also Send Feedback

Overload List

Name | Description
ToYaml()()() | Convert YamlNode to a YAML text.
ToYaml(Stream) | Convert YamlNode to a YAML text and save it to Stream s.
ToYaml(TextWriter) | Convert YamlNode to a YAML text and save it to TextWriter tw.
ToYaml(YamlConfig) | Convert YamlNode to a YAML text.
ToYaml(Stream, YamlConfig) | Convert YamlNode to a YAML text and save it to Stream s.
ToYaml(TextWriter, YamlConfig) | Convert YamlNode to a YAML text and save it to TextWriter tw.

See Also

YamlNode Class
YamlNode Members


ToYaml Method

[image]

YAML Serializer
YamlNode..::.ToYaml Method
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string ToYaml()
Visual Basic (Declaration)
Public Function ToYaml As String
Visual C++
public:
String^ ToYaml()

Return Value

YAML stream.

See Also

YamlNode Class
ToYaml Overload


ToYaml Method (Stream)

[image]

YAML Serializer
YamlNode..::.ToYaml Method (Stream)
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text and save it to Stream s.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void ToYaml(
    Stream s
)
Visual Basic (Declaration)
Public Sub ToYaml ( _
    s As Stream _
)
Visual C++
public:
void ToYaml(
    Stream^ s
)

Parameters

s
Type: System.IO..::.Stream
Stream to output.

See Also

YamlNode Class
ToYaml Overload


ToYaml Method (TextWriter)

[image]

YAML Serializer
YamlNode..::.ToYaml Method (TextWriter)
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text and save it to TextWriter tw.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void ToYaml(
    TextWriter tw
)
Visual Basic (Declaration)
Public Sub ToYaml ( _
    tw As TextWriter _
)
Visual C++
public:
void ToYaml(
    TextWriter^ tw
)

Parameters

tw
Type: System.IO..::.TextWriter
TextWriter to output.

See Also

YamlNode Class
ToYaml Overload


ToYaml Method (YamlConfig)

[image]

YAML Serializer
YamlNode..::.ToYaml Method (YamlConfig)
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string ToYaml(
    YamlConfig config
)
Visual Basic (Declaration)
Public Function ToYaml ( _
    config As YamlConfig _
) As String
Visual C++
public:
String^ ToYaml(
    YamlConfig^ config
)

Parameters

config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

Return Value

YAML stream.

See Also

YamlNode Class
ToYaml Overload


ToYaml Method (Stream, YamlConfig)

[image]

YAML Serializer
YamlNode..::.ToYaml Method (Stream, YamlConfig)
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text and save it to Stream s.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void ToYaml(
    Stream s,
    YamlConfig config
)
Visual Basic (Declaration)
Public Sub ToYaml ( _
    s As Stream, _
    config As YamlConfig _
)
Visual C++
public:
void ToYaml(
    Stream^ s,
    YamlConfig^ config
)

Parameters

s
Type: System.IO..::.Stream
Stream to output.
config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

See Also

YamlNode Class
ToYaml Overload


ToYaml Method (TextWriter, YamlConfig)

[image]

YAML Serializer
YamlNode..::.ToYaml Method (TextWriter, YamlConfig)
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text and save it to TextWriter tw.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void ToYaml(
    TextWriter tw,
    YamlConfig config
)
Visual Basic (Declaration)
Public Sub ToYaml ( _
    tw As TextWriter, _
    config As YamlConfig _
)
Visual C++
public:
void ToYaml(
    TextWriter^ tw,
    YamlConfig^ config
)

Parameters

tw
Type: System.IO..::.TextWriter
TextWriter to output.
config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

See Also

YamlNode Class
ToYaml Overload


ToYamlFile Method

[image] [image]

YAML Serializer
YamlNode..::.ToYamlFile Method
YamlNode Class See Also Send Feedback

Overload List

Name | Description
ToYamlFile(String) | Convert YamlNode to a YAML text and save it to the file.
ToYamlFile(String, YamlConfig) | Convert YamlNode to a YAML text and save it to the file.

See Also

YamlNode Class
YamlNode Members


ToYamlFile Method (String)

[image]

YAML Serializer
YamlNode..::.ToYamlFile Method (String)
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text and save it to the file.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void ToYamlFile(
    string FileName
)
Visual Basic (Declaration)
Public Sub ToYamlFile ( _
    FileName As String _
)
Visual C++
public:
void ToYamlFile(
    String^ FileName
)

Parameters

FileName
Type: System..::.String
Name of the file to output

See Also

YamlNode Class
ToYamlFile Overload


ToYamlFile Method (String, YamlConfig)

[image]

YAML Serializer
YamlNode..::.ToYamlFile Method (String, YamlConfig)
YamlNode Class See Also Send Feedback
Convert YamlNode to a YAML text and save it to the file.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void ToYamlFile(
    string FileName,
    YamlConfig config
)
Visual Basic (Declaration)
Public Sub ToYamlFile ( _
    FileName As String, _
    config As YamlConfig _
)
Visual C++
public:
void ToYamlFile(
    String^ FileName,
    YamlConfig^ config
)

Parameters

FileName
Type: System..::.String
Name of the file to output
config
Type: System.Yaml..::.YamlConfig
YAML configuration to customize serialization.

See Also

YamlNode Class
ToYamlFile Overload


YamlNode Properties

[image] [image]

YAML Serializer
YamlNode Properties
YamlNode Class See Also Send Feedback

The YamlNode type exposes the following members.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time.
DefaultConfig | Gets or sets the default configuration to customize serialization of YamlNode.
DefaultTagPrefix | Gets YAML's default tag prefix.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time.
Tag | YAML Tag for this node, which represents the type of node's value.

See Also

YamlNode Class


Column Property

[image]

YAML Serializer
YamlNode..::.Column Property
YamlNode Class See Also Send Feedback
Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public int Column { get; set; }
Visual Basic (Declaration)
Public Property Column As Integer
Visual C++
public:
property int Column {
    int get ();
    void set (int value);
}

See Also

YamlNode Class


DefaultConfig Property

[image]

YAML Serializer
YamlNode..::.DefaultConfig Property
YamlNode Class See Also Send Feedback
Gets or sets the default configuration to customize serialization of YamlNode.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static YamlConfig DefaultConfig { get; set; }
Visual Basic (Declaration)
Public Shared Property DefaultConfig As YamlConfig
Visual C++
public:
static property YamlConfig^ DefaultConfig {
    YamlConfig^ get ();
    void set (YamlConfig^ value);
}

See Also

YamlNode Class


DefaultTagPrefix Property

[image]

YAML Serializer
YamlNode..::.DefaultTagPrefix Property
YamlNode Class See Also Send Feedback
Gets YAML's default tag prefix.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static string DefaultTagPrefix { get; private set; }
Visual Basic (Declaration)
Public Shared Property DefaultTagPrefix As String
Visual C++
public:
static property String^ DefaultTagPrefix {
    String^ get ();
    void set (String^ value);
}

Field Value

"tag:yaml.org,2002:"

See Also

YamlNode Class


Raw Property

[image]

YAML Serializer
YamlNode..::.Raw Property
YamlNode Class See Also Send Feedback
Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public int Raw { get; set; }
Visual Basic (Declaration)
Public Property Raw As Integer
Visual C++
public:
property int Raw {
    int get ();
    void set (int value);
}

See Also

YamlNode Class


Tag Property

[image]

YAML Serializer
YamlNode..::.Tag Property
YamlNode Class See Also Send Feedback
YAML Tag for this node, which represents the type of node's value.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string Tag { get; set; }
Visual Basic (Declaration)
Public Property Tag As String
Visual C++
public:
property String^ Tag {
    String^ get ();
    void set (String^ value);
}

Remarks

YAML standard types has tags in a form of "tag:yaml.org,2002:???". Well known tags are tag:yaml.org,2002:null, tag:yaml.org,2002:bool, tag:yaml.org,2002:int, tag:yaml.org,2002:str, tag:yaml.org,2002:map, tag:yaml.org,2002:seq, tag:yaml.org,2002:float and tag:yaml.org,2002:timestamp.

See Also

YamlNode Class


YamlNode Events

[image] [image]

YAML Serializer
YamlNode Events
YamlNode Class See Also Send Feedback

The YamlNode type exposes the following members.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed.

See Also

YamlNode Class


Changed Event

[image]

YAML Serializer
YamlNode..::.Changed Event
YamlNode Class See Also Send Feedback
Invoked when the node's content or its childrens' content was changed.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public event EventHandler Changed
Visual Basic (Declaration)
Public Event Changed As EventHandler
Visual C++
public:
virtual  event EventHandler^ Changed {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}

See Also

YamlNode Class


YamlNodeManipulator Class

[image]

YAML Serializer
YamlNodeManipulator Class
Members Example See Also Send Feedback
Implements utility functions to instantiating YamlNode's

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public class YamlNodeManipulator
Visual Basic (Declaration)
Public Class YamlNodeManipulator
Visual C++
public ref class YamlNodeManipulator

Examples

CopyC#
var node_tree = seq(
    str("abc"),
    str("def"),
    map(
        str("key"), str("value"),
        str("key2"), seq( str("value2a"), str("value2b") )
    ),
    str("2"), // !!str
    str("!!int", "2")
);

string yaml = node_tree.ToYaml();

// %YAML 1.2
// ---
// - abc
// - def
// - key: value
//   key2: [ value2a, value2b ]
// - "2"         # !!str
// - 2           # !!int
// ...

Inheritance Hierarchy

System..::.Object
System.Yaml..::.YamlNodeManipulator

See Also

YamlNodeManipulator Members


YamlNodeManipulator Members

[image] [image]

YAML Serializer
YamlNodeManipulator Members
YamlNodeManipulator Class Constructors Methods See Also Send Feedback

The YamlNodeManipulator type exposes the following members.

Constructors

Name | Description
YamlNodeManipulator | Initializes a new instance of the YamlNodeManipulator class

Methods

Name | Description
Equals | (Inherited from Object.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Object.)
GetType | (Inherited from Object.)
map | Create a mapping node. Tag is set to be "!!map".
map_tag | Create a mapping node.
MemberwiseClone | (Inherited from Object.)
seq | Create a sequence node. Tag is set to be "!!seq".
seq_tag | Create a sequence node.
str | Overloaded.
ToString | (Inherited from Object.)

See Also

YamlNodeManipulator Class


YamlNodeManipulator Constructor

[image]

YAML Serializer
YamlNodeManipulator Constructor
YamlNodeManipulator Class See Also Send Feedback
Initializes a new instance of the YamlNodeManipulator class

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlNodeManipulator()
Visual Basic (Declaration)
Public Sub New
Visual C++
public:
YamlNodeManipulator()

See Also

YamlNodeManipulator Class


YamlNodeManipulator Methods

[image] [image]

YAML Serializer
YamlNodeManipulator Methods
YamlNodeManipulator Class See Also Send Feedback

The YamlNodeManipulator type exposes the following members.

Methods

Name | Description
Equals | (Inherited from Object.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Object.)
GetType | (Inherited from Object.)
map | Create a mapping node. Tag is set to be "!!map".
map_tag | Create a mapping node.
MemberwiseClone | (Inherited from Object.)
seq | Create a sequence node. Tag is set to be "!!seq".
seq_tag | Create a sequence node.
str | Overloaded.
ToString | (Inherited from Object.)

See Also

YamlNodeManipulator Class


map Method

[image]

YAML Serializer
YamlNodeManipulator..::.map Method
YamlNodeManipulator Class See Also Send Feedback
Create a mapping node. Tag is set to be "!!map".

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected static YamlMapping map(
    params YamlNode[] nodes
)
Visual Basic (Declaration)
Protected Shared Function map ( _
    ParamArray nodes As YamlNode() _
) As YamlMapping
Visual C++
protected:
static YamlMapping^ map(
    ... array<YamlNode^>^ nodes
)

Parameters

nodes
Type: array< System.Yaml..::.YamlNode >[]()[]
Sequential list of key/value pairs.

Return Value

Created mapping node.

See Also

YamlNodeManipulator Class


map_tag Method

[image]

YAML Serializer
YamlNodeManipulator..::.map_tag Method
YamlNodeManipulator Class See Also Send Feedback
Create a mapping node.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected static YamlMapping map_tag(
    string tag,
    params YamlNode[] nodes
)
Visual Basic (Declaration)
Protected Shared Function map_tag ( _
    tag As String, _
    ParamArray nodes As YamlNode() _
) As YamlMapping
Visual C++
protected:
static YamlMapping^ map_tag(
    String^ tag,
    ... array<YamlNode^>^ nodes
)

Parameters

tag
Type: System..::.String
Tag for the mapping.
nodes
Type: array< System.Yaml..::.YamlNode >[]()[]
Sequential list of key/value pairs.

Return Value

Created mapping node.

See Also

YamlNodeManipulator Class


seq Method

[image]

YAML Serializer
YamlNodeManipulator..::.seq Method
YamlNodeManipulator Class See Also Send Feedback
Create a sequence node. Tag is set to be "!!seq".

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected static YamlSequence seq(
    params YamlNode[] nodes
)
Visual Basic (Declaration)
Protected Shared Function seq ( _
    ParamArray nodes As YamlNode() _
) As YamlSequence
Visual C++
protected:
static YamlSequence^ seq(
    ... array<YamlNode^>^ nodes
)

Parameters

nodes
Type: array< System.Yaml..::.YamlNode >[]()[]
Child nodes.

Return Value

Created sequence node.

See Also

YamlNodeManipulator Class


seq_tag Method

[image]

YAML Serializer
YamlNodeManipulator..::.seq_tag Method
YamlNodeManipulator Class See Also Send Feedback
Create a sequence node.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected static YamlSequence seq_tag(
    string tag,
    params YamlNode[] nodes
)
Visual Basic (Declaration)
Protected Shared Function seq_tag ( _
    tag As String, _
    ParamArray nodes As YamlNode() _
) As YamlSequence
Visual C++
protected:
static YamlSequence^ seq_tag(
    String^ tag,
    ... array<YamlNode^>^ nodes
)

Parameters

tag
Type: System..::.String
Tag for the seuqnce.
nodes
Type: array< System.Yaml..::.YamlNode >[]()[]
Child nodes.

Return Value

Created sequence node.

See Also

YamlNodeManipulator Class


str Method

[image] [image]

YAML Serializer
YamlNodeManipulator..::.str Method
YamlNodeManipulator Class See Also Send Feedback

Overload List

Name | Description
str(String) | Create a scalar node. Tag is set to be "!!str".
str(String, String) | Create a scalar node.

See Also

YamlNodeManipulator Class
YamlNodeManipulator Members


str Method (String)

[image]

YAML Serializer
YamlNodeManipulator..::.str Method (String)
YamlNodeManipulator Class Example See Also Send Feedback
Create a scalar node. Tag is set to be "!!str".

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected static YamlScalar str(
    string value
)
Visual Basic (Declaration)
Protected Shared Function str ( _
    value As String _
) As YamlScalar
Visual C++
protected:
static YamlScalar^ str(
    String^ value
)

Parameters

value
Type: System..::.String
Value for the scalar node.

Return Value

Created scalar node.

Examples

CopyC#
var node_tree = seq(
    str("abc"),
    str("def"),
    map(
        str("key"), str("value"),
        str("key2"), seq( str("value2a"), str("value2b") )
    ),
    str("2"), // !!str
    str("!!int", "2")
);

string yaml = node_tree.ToYaml();

// %YAML 1.2
// ---
// - abc
// - def
// - key: value
//   key2: [ value2a, value2b ]
// - "2"         # !!str
// - 2           # !!int
// ...

See Also

YamlNodeManipulator Class
str Overload


str Method (String, String)

[image]

YAML Serializer
YamlNodeManipulator..::.str Method (String, String)
YamlNodeManipulator Class See Also Send Feedback
Create a scalar node.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected static YamlScalar str(
    string tag,
    string value
)
Visual Basic (Declaration)
Protected Shared Function str ( _
    tag As String, _
    value As String _
) As YamlScalar
Visual C++
protected:
static YamlScalar^ str(
    String^ tag,
    String^ value
)

Parameters

tag
Type: System..::.String
Tag for the scalar node.
value
Type: System..::.String
Value for the scalar node.

Return Value

Created scalar node.

See Also

YamlNodeManipulator Class
str Overload


YamlScalar Class

[image]

YAML Serializer
YamlScalar Class
Members Example See Also Send Feedback
Represents a scalar node in a YAML document.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public class YamlScalar : YamlNode
Visual Basic (Declaration)
Public Class YamlScalar _
    Inherits YamlNode
Visual C++
public ref class YamlScalar : public YamlNode

Examples

CopyC#
var string_node = new YamlNode("abc");
Assert.AreEqual("!!str", string_node.ShorthandTag());

var int_node1= new YamlNode(YamlNode.DefaultTagPrefix + "int", "1");
Assert.AreEqual("!!int", int_node1.ShorthandTag());

// shorthand tag style can be specified
var int_node2= new YamlNode("!!int", "1");
Assert.AreEqual(YamlNode.DefaultTagPrefix + "int", int_node1.Tag);
Assert.AreEqual("!!int", int_node1.ShorthandTag());

// or use implicit conversion
YamlNode int_node3 = 1;

// YamlNodes Equals to another node when their values are equal.
Assert.AreEqual(int_node1, int_node2);

// Of course, they are different if compaired by references.
Assert.IsTrue(int_node1 != int_node2);

Inheritance Hierarchy

System..::.Object
System.Yaml..::.YamlNode
System.Yaml..::.YamlScalar

See Also

YamlScalar Members


YamlScalar Members

[image] [image]

YAML Serializer
YamlScalar Members
YamlScalar Class Constructors Methods Properties Events See Also Send Feedback

The YamlScalar type exposes the following members.

Constructors

Name | Description
YamlScalar | Overloaded.

Methods

Name | Description
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Returns the hash code. The returned value will be cached until OnChanged()()() is called. (Overrides YamlNode..::.GetHashCodeCore()()().)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Overrides YamlNode..::.OnChanged()()().)
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

Operators

Name | Description
Implicit | Overloaded.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
NativeObject | When the node has YAML's standard scalar type, the native object corresponding to it can be got from this property. To see if this property contains a valid data, refer to NativeObjectAvailable.
NativeObjectAvailable | Gets if NativeObject contains a valid content.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)
Value | String expression of the node value.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlScalar Class


YamlScalar Constructor

[image] [image]

YAML Serializer
YamlScalar Constructor
YamlScalar Class See Also Send Feedback

Overload List

Name | Description
YamlScalar()()() | Create empty string node.
YamlScalar(Boolean) | Initialize a bool node that has value as its content.
YamlScalar(DateTime) | Initialize a timestamp node that has value as its content.
YamlScalar(Double) | Initialize a float node that has value as its content.
YamlScalar(Int32) | Initialize an integer node that has value as its content.
YamlScalar(String) | Initialize string node that has value as its content.
YamlScalar(String, String) | Create a scalar node with arbitral tag.

See Also

YamlScalar Class
YamlScalar Members


YamlScalar Constructor

[image]

YAML Serializer
YamlScalar Constructor
YamlScalar Class See Also Send Feedback
Create empty string node.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlScalar()
Visual Basic (Declaration)
Public Sub New
Visual C++
public:
YamlScalar()

See Also

YamlScalar Class
YamlScalar Overload


YamlScalar Constructor (Boolean)

[image]

YAML Serializer
YamlScalar Constructor (Boolean)
YamlScalar Class See Also Send Feedback
Initialize a bool node that has value as its content.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlScalar(
    bool value
)
Visual Basic (Declaration)
Public Sub New ( _
    value As Boolean _
)
Visual C++
public:
YamlScalar(
    bool value
)

Parameters

value
Type: System..::.Boolean

[Missing <param name="value"/> documentation for "M:System.Yaml.YamlScalar.#ctor(System.Boolean)"]

See Also

YamlScalar Class
YamlScalar Overload


YamlScalar Constructor (DateTime)

[image]

YAML Serializer
YamlScalar Constructor (DateTime)
YamlScalar Class See Also Send Feedback
Initialize a timestamp node that has value as its content.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlScalar(
    DateTime value
)
Visual Basic (Declaration)
Public Sub New ( _
    value As DateTime _
)
Visual C++
public:
YamlScalar(
    DateTime value
)

Parameters

value
Type: System..::.DateTime

[Missing <param name="value"/> documentation for "M:System.Yaml.YamlScalar.#ctor(System.DateTime)"]

See Also

YamlScalar Class
YamlScalar Overload


YamlScalar Constructor (Double)

[image]

YAML Serializer
YamlScalar Constructor (Double)
YamlScalar Class See Also Send Feedback
Initialize a float node that has value as its content.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlScalar(
    double value
)
Visual Basic (Declaration)
Public Sub New ( _
    value As Double _
)
Visual C++
public:
YamlScalar(
    double value
)

Parameters

value
Type: System..::.Double

[Missing <param name="value"/> documentation for "M:System.Yaml.YamlScalar.#ctor(System.Double)"]

See Also

YamlScalar Class
YamlScalar Overload


YamlScalar Constructor (Int32)

[image]

YAML Serializer
YamlScalar Constructor (Int32)
YamlScalar Class See Also Send Feedback
Initialize an integer node that has value as its content.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlScalar(
    int value
)
Visual Basic (Declaration)
Public Sub New ( _
    value As Integer _
)
Visual C++
public:
YamlScalar(
    int value
)

Parameters

value
Type: System..::.Int32

[Missing <param name="value"/> documentation for "M:System.Yaml.YamlScalar.#ctor(System.Int32)"]

See Also

YamlScalar Class
YamlScalar Overload


YamlScalar Constructor (String)

[image]

YAML Serializer
YamlScalar Constructor (String)
YamlScalar Class See Also Send Feedback
Initialize string node that has value as its content.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlScalar(
    string value
)
Visual Basic (Declaration)
Public Sub New ( _
    value As String _
)
Visual C++
public:
YamlScalar(
    String^ value
)

Parameters

value
Type: System..::.String
Value of the node.

See Also

YamlScalar Class
YamlScalar Overload


YamlScalar Constructor (String, String)

[image]

YAML Serializer
YamlScalar Constructor (String, String)
YamlScalar Class See Also Send Feedback
Create a scalar node with arbitral tag.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlScalar(
    string tag,
    string value
)
Visual Basic (Declaration)
Public Sub New ( _
    tag As String, _
    value As String _
)
Visual C++
public:
YamlScalar(
    String^ tag,
    String^ value
)

Parameters

tag
Type: System..::.String
Tag to the node.
value
Type: System..::.String
Value of the node.

See Also

YamlScalar Class
YamlScalar Overload


YamlScalar Methods

[image] [image]

YAML Serializer
YamlScalar Methods
YamlScalar Class See Also Send Feedback

The YamlScalar type exposes the following members.

Methods

Name | Description
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Returns the hash code. The returned value will be cached until OnChanged()()() is called. (Overrides YamlNode..::.GetHashCodeCore()()().)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Overrides YamlNode..::.OnChanged()()().)
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

Operators

Name | Description
Implicit | Overloaded.

See Also

YamlScalar Class


GetHashCodeCore Method

[image]

YAML Serializer
YamlScalar..::.GetHashCodeCore Method
YamlScalar Class See Also Send Feedback
Returns the hash code. The returned value will be cached until OnChanged()()() is called.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected override int GetHashCodeCore()
Visual Basic (Declaration)
Protected Overrides Function GetHashCodeCore As Integer
Visual C++
protected:
virtual int GetHashCodeCore() override

Return Value

Hash code

See Also

YamlScalar Class


Implicit Method

[image] [image]

YAML Serializer
YamlScalar..::.Implicit Method
YamlScalar Class See Also Send Feedback

Overload List

Name | Description
Implicit(Boolean) | Implicit conversion from string to YamlScalar.
Implicit(DateTime) | Implicit conversion from DateTime to YamlScalar.
Implicit(Double) | Implicit conversion from string to YamlScalar.
Implicit(Int32) | Implicit conversion from string to YamlScalar.
Implicit(String) | Implicit conversion from string to YamlScalar.

See Also

YamlScalar Class
YamlScalar Members


Implicit Operator

[image]

YAML Serializer
YamlScalar..::.Implicit Operator
YamlScalar Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlScalar (
    bool value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As Boolean _
) As YamlScalar
Visual C++
static implicit operator YamlScalar^ (
    bool value
)

Parameters

value
Type: System..::.Boolean
Value to be converted.

Return Value

Conversion result.

See Also

YamlScalar Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlScalar..::.Implicit Operator
YamlScalar Class See Also Send Feedback
Implicit conversion from DateTime to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlScalar (
    DateTime value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As DateTime _
) As YamlScalar
Visual C++
static implicit operator YamlScalar^ (
    DateTime value
)

Parameters

value
Type: System..::.DateTime
Value to be converted.

Return Value

Conversion result.

See Also

YamlScalar Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlScalar..::.Implicit Operator
YamlScalar Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlScalar (
    double value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As Double _
) As YamlScalar
Visual C++
static implicit operator YamlScalar^ (
    double value
)

Parameters

value
Type: System..::.Double
Value to be converted.

Return Value

Conversion result.

See Also

YamlScalar Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlScalar..::.Implicit Operator
YamlScalar Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlScalar (
    int value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As Integer _
) As YamlScalar
Visual C++
static implicit operator YamlScalar^ (
    int value
)

Parameters

value
Type: System..::.Int32
Value to be converted.

Return Value

Conversion result.

See Also

YamlScalar Class
Implicit Overload


Implicit Operator

[image]

YAML Serializer
YamlScalar..::.Implicit Operator
YamlScalar Class See Also Send Feedback
Implicit conversion from string to YamlScalar.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public static implicit operator YamlScalar (
    string value
)
Visual Basic (Declaration)
Public Shared Widening Operator CType ( _
    value As String _
) As YamlScalar
Visual C++
static implicit operator YamlScalar^ (
    String^ value
)

Parameters

value
Type: System..::.String
Value to be converted.

Return Value

Conversion result.

See Also

YamlScalar Class
Implicit Overload


OnChanged Method

[image]

YAML Serializer
YamlScalar..::.OnChanged Method
YamlScalar Class See Also Send Feedback
Call this function when the content of the node is changed.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected override void OnChanged()
Visual Basic (Declaration)
Protected Overrides Sub OnChanged
Visual C++
protected:
virtual void OnChanged() override

See Also

YamlScalar Class


ToYaml Method

[image] [image]

YAML Serializer
YamlScalar..::.ToYaml Method
YamlScalar Class See Also Send Feedback

Overload List

Name | Description
ToYaml()()() | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)
ToYaml(YamlConfig) | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream, YamlConfig) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter, YamlConfig) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)

See Also

YamlScalar Class
YamlScalar Members


ToYamlFile Method

[image] [image]

YAML Serializer
YamlScalar..::.ToYamlFile Method
YamlScalar Class See Also Send Feedback

Overload List

Name | Description
ToYamlFile(String) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)
ToYamlFile(String, YamlConfig) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)

See Also

YamlScalar Class
YamlScalar Members


YamlScalar Properties

[image] [image]

YAML Serializer
YamlScalar Properties
YamlScalar Class See Also Send Feedback

The YamlScalar type exposes the following members.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
NativeObject | When the node has YAML's standard scalar type, the native object corresponding to it can be got from this property. To see if this property contains a valid data, refer to NativeObjectAvailable.
NativeObjectAvailable | Gets if NativeObject contains a valid content.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)
Value | String expression of the node value.

See Also

YamlScalar Class


NativeObject Property

[image]

YAML Serializer
YamlScalar..::.NativeObject Property
YamlScalar Class See Also Send Feedback

When the node has YAML's standard scalar type, the native object corresponding to it can be got from this property. To see if this property contains a valid data, refer to NativeObjectAvailable.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public Object NativeObject { get; private set; }
Visual Basic (Declaration)
Public Property NativeObject As Object
Visual C++
public:
property Object^ NativeObject {
    Object^ get ();
    void set (Object^ value);
}

Remarks

This property is available when DefaultConfig.TagResolver()()() contains an entry for the nodes tag and defines how to decode the Value property into native objects.

When this property is available, equality of the scalar node is evaluated by comparing the NativeObject properties by the language default equality operator.

Exceptions

Exception | Condition
System..::.InvalidOperationException | This property is not available. See NativeObjectAvailable.

See Also

YamlScalar Class


NativeObjectAvailable Property

[image]

YAML Serializer
YamlScalar..::.NativeObjectAvailable Property
YamlScalar Class See Also Send Feedback
Gets if NativeObject contains a valid content.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool NativeObjectAvailable { get; private set; }
Visual Basic (Declaration)
Public Property NativeObjectAvailable As Boolean
Visual C++
public:
property bool NativeObjectAvailable {
    bool get ();
    void set (bool value);
}

See Also

YamlScalar Class


Value Property

[image]

YAML Serializer
YamlScalar..::.Value Property
YamlScalar Class See Also Send Feedback
String expression of the node value.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string Value { get; set; }
Visual Basic (Declaration)
Public Property Value As String
Visual C++
public:
property String^ Value {
    String^ get ();
    void set (String^ value);
}

See Also

YamlScalar Class


YamlScalar Events

[image] [image]

YAML Serializer
YamlScalar Events
YamlScalar Class See Also Send Feedback

The YamlScalar type exposes the following members.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlScalar Class


YamlSequence Class

[image]

YAML Serializer
YamlSequence Class
Members See Also Send Feedback
Represents a sequence node in a YAML document. Use IList<YamlNode> interface to manipulate child nodes.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public class YamlSequence : YamlComplexNode,
    IList<YamlNode>, ICollection<YamlNode>, IEnumerable<YamlNode>,
    IEnumerable, IDisposable
Visual Basic (Declaration)
Public Class YamlSequence _
    Inherits YamlComplexNode _
    Implements IList(Of YamlNode), ICollection(Of YamlNode),  _
    IEnumerable(Of YamlNode), IEnumerable, IDisposable
Visual C++
public ref class YamlSequence : public YamlComplexNode,
    IList<YamlNode^>, ICollection<YamlNode^>, IEnumerable<YamlNode^>,
    IEnumerable, IDisposable

Inheritance Hierarchy

System..::.Object
System.Yaml..::.YamlNode
System.Yaml..::.YamlComplexNode
System.Yaml..::.YamlSequence

See Also

YamlSequence Members


YamlSequence Members

[image] [image]

YAML Serializer
YamlSequence Members
YamlSequence Class Constructors Methods Properties Events See Also Send Feedback

The YamlSequence type exposes the following members.

Constructors

Name | Description
YamlSequence | Create a sequence node that has nodes as its child.

Methods

Name | Description
Add | Adds an item to the YamlSequence.
Clear | Removes all nodes from the YamlSequence.
Contains | Determines whether a sequence contains a child node that equals to the specified value by using the default equality comparer.
CopyTo | Copies the child nodes of the YamlSequence to an Array, starting at a particular Array index.
Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetEnumerator | Returns an enumerator that iterates through the all child nodes.
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Calculate hash code from Tag property and all child nodes. The result is cached. (Inherited from YamlComplexNode.)
GetHashCodeCoreSub | Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree. (Overrides YamlComplexNode..::.GetHashCodeCoreSub(Int32, Dictionary<(Of <(YamlNode, Int32>)>)).)
GetType | (Inherited from Object.)
IndexOf | Determines the index of a specific child node in the YamlSequence.
Insert | Inserts an item to the YamlSequence at the specified index.
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Inherited from YamlNode.)
Remove | Removes the first occurrence of a specific node from the YamlSequence.
RemoveAt | Removes the YamlSequence item at the specified index.
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Count | Gets the number of child nodes of the YamlSequence.
Item | Gets or sets the node at the specified index.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlSequence Class


YamlSequence Constructor

[image]

YAML Serializer
YamlSequence Constructor
YamlSequence Class See Also Send Feedback
Create a sequence node that has nodes as its child.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlSequence(
    params YamlNode[] nodes
)
Visual Basic (Declaration)
Public Sub New ( _
    ParamArray nodes As YamlNode() _
)
Visual C++
public:
YamlSequence(
    ... array<YamlNode^>^ nodes
)

Parameters

nodes
Type: array< System.Yaml..::.YamlNode >[]()[]
Child nodes of the sequence.

See Also

YamlSequence Class


YamlSequence Methods

[image] [image]

YAML Serializer
YamlSequence Methods
YamlSequence Class See Also Send Feedback

The YamlSequence type exposes the following members.

Methods

Name | Description
Add | Adds an item to the YamlSequence.
Clear | Removes all nodes from the YamlSequence.
Contains | Determines whether a sequence contains a child node that equals to the specified value by using the default equality comparer.
CopyTo | Copies the child nodes of the YamlSequence to an Array, starting at a particular Array index.
Dispose | Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Equals | Returns true if obj is of same type as the YamlNode and its content is also logically same. (Inherited from YamlNode.)
Finalize | (Inherited from Object.)
GetEnumerator | Returns an enumerator that iterates through the all child nodes.
GetHashCode | Serves as a hash function for a particular type. Hash code is calculated using Tag and Value properties. (Inherited from YamlNode.)
GetHashCodeCore | Calculate hash code from Tag property and all child nodes. The result is cached. (Inherited from YamlComplexNode.)
GetHashCodeCoreSub | Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree. (Overrides YamlComplexNode..::.GetHashCodeCoreSub(Int32, Dictionary<(Of <(YamlNode, Int32>)>)).)
GetType | (Inherited from Object.)
IndexOf | Determines the index of a specific child node in the YamlSequence.
Insert | Inserts an item to the YamlSequence at the specified index.
MemberwiseClone | (Inherited from Object.)
OnChanged | Call this function when the content of the node is changed. (Inherited from YamlNode.)
Remove | Removes the first occurrence of a specific node from the YamlSequence.
RemoveAt | Removes the YamlSequence item at the specified index.
ShorthandTag | YAML Tag for this node, which represents the type of node's value. The Tag property is returned in a shorthand style. (Inherited from YamlNode.)
ToString | Returns a String that represents the current Object. (Inherited from YamlNode.)
ToYaml | Overloaded.
ToYamlFile | Overloaded.

See Also

YamlSequence Class


Add Method

[image]

YAML Serializer
YamlSequence..::.Add Method
YamlSequence Class See Also Send Feedback
Adds an item to the YamlSequence.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Add(
    YamlNode item
)
Visual Basic (Declaration)
Public Sub Add ( _
    item As YamlNode _
)
Visual C++
public:
virtual void Add(
    YamlNode^ item
) sealed

Parameters

item
Type: System.Yaml..::.YamlNode
The node to add to the YamlSequence.

Implements

ICollection<(Of <(T>)>)..::.Add(T)

See Also

YamlSequence Class


Clear Method

[image]

YAML Serializer
YamlSequence..::.Clear Method
YamlSequence Class See Also Send Feedback
Removes all nodes from the YamlSequence.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Clear()
Visual Basic (Declaration)
Public Sub Clear
Visual C++
public:
virtual void Clear() sealed

Implements

ICollection<(Of <(T>)>)..::.Clear()()()

See Also

YamlSequence Class


Contains Method

[image]

YAML Serializer
YamlSequence..::.Contains Method
YamlSequence Class Example See Also Send Feedback
Determines whether a sequence contains a child node that equals to the specified value by using the default equality comparer.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool Contains(
    YamlNode value
)
Visual Basic (Declaration)
Public Function Contains ( _
    value As YamlNode _
) As Boolean
Visual C++
public:
virtual bool Contains(
    YamlNode^ value
) sealed

Parameters

value
Type: System.Yaml..::.YamlNode
The node value to locate in the sequence.

Return Value

true If the sequence contains an node that has the specified value; otherwise, false.

Implements

ICollection<(Of <(T>)>)..::.Contains(T)

Examples

CopyC#
var seq = new YamlSequence(new YamlScalar("a"));

// different object that has same value
Assert.IsTrue(seq.Contains(new YamlScalar("a")));

// different value
Assert.IsFalse(s.Contains(str("b")));

See Also

YamlSequence Class


CopyTo Method

[image]

YAML Serializer
YamlSequence..::.CopyTo Method
YamlSequence Class See Also Send Feedback
Copies the child nodes of the YamlSequence to an Array, starting at a particular Array index.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void CopyTo(
    YamlNode[] array,
    int arrayIndex
)
Visual Basic (Declaration)
Public Sub CopyTo ( _
    array As YamlNode(), _
    arrayIndex As Integer _
)
Visual C++
public:
virtual void CopyTo(
    array<YamlNode^>^ array,
    int arrayIndex
) sealed

Parameters

array
Type: array< System.Yaml..::.YamlNode >[]()[]
The one-dimensional Array that is the destination of the elements copied from YamlSequence.
arrayIndex
Type: System..::.Int32
The zero-based index in array at which copying begins.

Implements

ICollection<(Of <(T>)>)..::.CopyTo(array<T>[]()[], Int32)

Exceptions

Exception | Condition
System..::.ArgumentNullException | array is a null reference.
System..::.ArgumentOutOfRangeException | arrayIndex is less than 0.
System..::.ArgumentException | array is multidimensional. -or- The number of elements in the source YamlSequence is greater than the available space from arrayIndex to the end of the destination array.

See Also

YamlSequence Class


Dispose Method

[image]

YAML Serializer
YamlSequence..::.Dispose Method
YamlSequence Class See Also Send Feedback
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Dispose()
Visual Basic (Declaration)
Public Sub Dispose
Visual C++
public:
virtual void Dispose() sealed

Implements

IDisposable..::.Dispose()()()

See Also

YamlSequence Class


GetEnumerator Method

[image]

YAML Serializer
YamlSequence..::.GetEnumerator Method
YamlSequence Class See Also Send Feedback
Returns an enumerator that iterates through the all child nodes.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public IEnumerator<YamlNode> GetEnumerator()
Visual Basic (Declaration)
Public Function GetEnumerator As IEnumerator(Of YamlNode)
Visual C++
public:
virtual IEnumerator<YamlNode^>^ GetEnumerator() sealed

Return Value

An enumerator that iterates through the all child nodes.

Implements

IEnumerable<(Of <(T>)>)..::.GetEnumerator()()()

See Also

YamlSequence Class


GetHashCodeCoreSub Method

[image]

YAML Serializer
YamlSequence..::.GetHashCodeCoreSub Method
YamlSequence Class See Also Send Feedback
Calculates the hash code for a collection object. This function is called recursively on the child objects with the sub cache code repository for the nodes already appeared in the node tree.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
protected override int GetHashCodeCoreSub(
    int path,
    Dictionary<YamlNode, int> dict
)
Visual Basic (Declaration)
Protected Overrides Function GetHashCodeCoreSub ( _
    path As Integer, _
    dict As Dictionary(Of YamlNode, Integer) _
) As Integer
Visual C++
protected:
virtual int GetHashCodeCoreSub(
    int path,
    Dictionary<YamlNode^, int>^ dict
) override

Parameters

path
Type: System..::.Int32
The cache code for the path where this node was found.
dict
Type: System.Collections.Generic..::.Dictionary <(Of <( YamlNode, Int32 >)>)
Repository of the nodes that already appeared in the node tree. Sub hash code for the nodes can be refered to from this dictionary.

Return Value

[Missing <returns> documentation for "M:System.Yaml.YamlSequence.GetHashCodeCoreSub(System.Int32,System.Collections.Generic.Dictionary{System.Yaml.YamlNode,System.Int32})"]

See Also

YamlSequence Class


IndexOf Method

[image]

YAML Serializer
YamlSequence..::.IndexOf Method
YamlSequence Class See Also Send Feedback
Determines the index of a specific child node in the YamlSequence.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public int IndexOf(
    YamlNode item
)
Visual Basic (Declaration)
Public Function IndexOf ( _
    item As YamlNode _
) As Integer
Visual C++
public:
virtual int IndexOf(
    YamlNode^ item
) sealed

Parameters

item
Type: System.Yaml..::.YamlNode
The child node to locate in the YamlSequence.

Return Value

The index of item if found in the sequence; otherwise, -1.

Implements

IList<(Of <(T>)>)..::.IndexOf(T)

Remarks

If an node appears multiple times in the sequence, the IndexOf method always returns the first instance found.

See Also

YamlSequence Class


Insert Method

[image]

YAML Serializer
YamlSequence..::.Insert Method
YamlSequence Class See Also Send Feedback
Inserts an item to the YamlSequence at the specified index.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Insert(
    int index,
    YamlNode item
)
Visual Basic (Declaration)
Public Sub Insert ( _
    index As Integer, _
    item As YamlNode _
)
Visual C++
public:
virtual void Insert(
    int index,
    YamlNode^ item
) sealed

Parameters

index
Type: System..::.Int32
The zero-based index at which item should be inserted.
item
Type: System.Yaml..::.YamlNode
The node to insert into the YamlSequence.

Implements

IList<(Of <(T>)>)..::.Insert(Int32, T)

Remarks

If index equals the number of items in the YamlSequence, then item is appended to the sequence.

The nodes that follow the insertion point move down to accommodate the new node.

Exceptions

Exception | Condition
System..::.ArgumentOutOfRangeException | index is not a valid index in the YamlSequence.

See Also

YamlSequence Class


Remove Method

[image]

YAML Serializer
YamlSequence..::.Remove Method
YamlSequence Class See Also Send Feedback
Removes the first occurrence of a specific node from the YamlSequence.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public bool Remove(
    YamlNode node
)
Visual Basic (Declaration)
Public Function Remove ( _
    node As YamlNode _
) As Boolean
Visual C++
public:
virtual bool Remove(
    YamlNode^ node
) sealed

Parameters

node
Type: System.Yaml..::.YamlNode
The node to remove from the YamlSequence.

Return Value

true if node was successfully removed from the YamlSequence; otherwise, false. This method also returns false if node is not found in the original YamlSequence.

Implements

ICollection<(Of <(T>)>)..::.Remove(T)

See Also

YamlSequence Class


RemoveAt Method

[image]

YAML Serializer
YamlSequence..::.RemoveAt Method
YamlSequence Class See Also Send Feedback
Removes the YamlSequence item at the specified index.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void RemoveAt(
    int index
)
Visual Basic (Declaration)
Public Sub RemoveAt ( _
    index As Integer _
)
Visual C++
public:
virtual void RemoveAt(
    int index
) sealed

Parameters

index
Type: System..::.Int32
The zero-based index of the node to remove.

Implements

IList<(Of <(T>)>)..::.RemoveAt(Int32)

Remarks

The nodes that follow the removed node move up to occupy the vacated spot.

Exceptions

Exception | Condition
System..::.ArgumentOutOfRangeException | index is not a valid index in the YamlSequence.

See Also

YamlSequence Class


ToYaml Method

[image] [image]

YAML Serializer
YamlSequence..::.ToYaml Method
YamlSequence Class See Also Send Feedback

Overload List

Name | Description
ToYaml()()() | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)
ToYaml(YamlConfig) | Convert YamlNode to a YAML text. (Inherited from YamlNode.)
ToYaml(Stream, YamlConfig) | Convert YamlNode to a YAML text and save it to Stream s. (Inherited from YamlNode.)
ToYaml(TextWriter, YamlConfig) | Convert YamlNode to a YAML text and save it to TextWriter tw. (Inherited from YamlNode.)

See Also

YamlSequence Class
YamlSequence Members


ToYamlFile Method

[image] [image]

YAML Serializer
YamlSequence..::.ToYamlFile Method
YamlSequence Class See Also Send Feedback

Overload List

Name | Description
ToYamlFile(String) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)
ToYamlFile(String, YamlConfig) | Convert YamlNode to a YAML text and save it to the file. (Inherited from YamlNode.)

See Also

YamlSequence Class
YamlSequence Members


YamlSequence Properties

[image] [image]

YAML Serializer
YamlSequence Properties
YamlSequence Class See Also Send Feedback

The YamlSequence type exposes the following members.

Properties

Name | Description
Column | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Count | Gets the number of child nodes of the YamlSequence.
Item | Gets or sets the node at the specified index.
Raw | Position in a YAML document, where the node appears. Both ToYaml()()() and FromYaml(String) sets this property. When the node appeared multiple times in the document, this property returns the position where it appeared for the first time. (Inherited from YamlNode.)
Tag | YAML Tag for this node, which represents the type of node's value. (Inherited from YamlNode.)

See Also

YamlSequence Class


Count Property

[image]

YAML Serializer
YamlSequence..::.Count Property
YamlSequence Class See Also Send Feedback
Gets the number of child nodes of the YamlSequence.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public int Count { get; }
Visual Basic (Declaration)
Public ReadOnly Property Count As Integer
Visual C++
public:
virtual property int Count {
    int get () sealed;
}

Field Value

The number of child nodes of the sequence.

Implements

ICollection<(Of <(T>)>)..::.Count

See Also

YamlSequence Class


Item Property

[image]

YAML Serializer
YamlSequence..::.Item Property
YamlSequence Class See Also Send Feedback
Gets or sets the node at the specified index.

Namespace: System.Yaml
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlNode this[
    int index
] { get; set; }
Visual Basic (Declaration)
Public Default Property Item ( _
    index As Integer _
) As YamlNode
Visual C++
public:
virtual property YamlNode^ default[int index] {
    YamlNode^ get (int index) sealed;
    void set (int index, YamlNode^ value) sealed;
}

Parameters

index
Type: System..::.Int32
The zero-based index of the node to get or set.

Return Value

The node at the specified index.

Implements

IList<(Of <(T>)>)..::.Item[([(Int32])])

Remarks

This property provides the ability to access a specific node in the sequence by using the following syntax: mySequence[index].

Exceptions

Exception | Condition
System..::.ArgumentOutOfRangeException | index is not a valid index in the YamlSequence).

See Also

YamlSequence Class


YamlSequence Events

[image] [image]

YAML Serializer
YamlSequence Events
YamlSequence Class See Also Send Feedback

The YamlSequence type exposes the following members.

Events

Name | Description
Changed | Invoked when the node's content or its childrens' content was changed. (Inherited from YamlNode.)

See Also

YamlSequence Class


System.Yaml.Serialization Namespace

[image]

YAML Serializer
System.Yaml.Serialization Namespace
Send Feedback

What is this for?

This class library supports YAML file manipulation in two different contexts.

  1. One is to serialize / deserialize C# native objects into / from YAML text files. => [System.Yaml.Serialization.YamlSerializer]
  2. The other is manipulating generic YAML documents that does not represents C# object but does some logical data. => [System.Yaml.YamlNode]

Requirements

.NET 3.5 SP1

What is YAML?

YAML is a human friendly data serialization standard for all programming languages.

There is a good introduction in the YAML for .NET, Visual Studio and Powershell project.

According to that,
  1. YAML is easily readable by humans.
  2. YAML is consise and compact.
  3. YAML is expressive and extensible.

Another introduction can be found at Yaml Cookbook.

See The Official YAML Web Site for the language specification.

Note that the top page of The Official YAML Web Site is written as a valid YAML 1.2 document. It is definitely human friendly.

YamlSerizlizer class

For the first purpose, System.Yaml.Serialization.YamlSerializer class has instance methods [YamlSerializer.Serialize] and [YamlSerializer.Deserialize]. With these methods, C# native objects can be converted into / from YAML text without any preparations.

CopyC#
// Simple(?) array of objects
object obj = new object[]{
    "a",
    true,
    1,
    1.0,
    new Point(1,3),
    new YamlScalar("node")
};

var serializer = new YamlSerializer();

// Serialize it. How difficult!
string yaml = serializer.Serialize( obj );

// %YAML 1.2
// ---
// - "a"
// - true
// - 1
// - !!float 1
// - !<!System.Drawing.Point> 1,3
// - !<!YamlSerializer.YamlScalar>
//   Tag: "tag:yaml.org,2002:str"
//   Value: "node"
// ...

// Deserialize it.
object restored = serializer.Deserialize(yaml)[0];

// In general, you can serialize multiple objects in a YAML stream.
// So the Deserialize method returns an array of objects.

YamlNode class

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

See [YamlScalar], [YamlSequence] and [YamlMapping] classes for the actual data classes.

To read / write YAML text to compose / present [YamlNode] tree, the static method [YamlNode.FromYaml] and the instance method [YamlNode.ToYaml] are provided.

CopyC#
YamlNode[] nodes = YamlNode.FromYaml(new System.IO.FileStream("settings.yaml"));
string yaml = nodes[0].ToYaml();

Classes

Class Description
YamlSerializeAttribute
Specify the way to store a property or field of some class or structure. See YamlSerializer for detail.
YamlSerializer

YamlSerializer class has instance methods Serialize(Object) and Deserialize(String, array<Type>[]()[]), with which C# native objects can be converted into / from YAML text without any preparations.

CopyC#
var serializer = new YamlSerializer();
object obj = GetObjectToSerialize();
string yaml = serializer.Serialize(obj);
object restored = serializer.Deserialize(yaml);
Assert.AreEqual(obj, restored);

Enumerations

Enumeration | Description
YamlSerializeMethod | Specify the way to store a property or field of some class or structure. See YamlSerializer for detail.


YamlSerializeAttribute Class

[image]

YAML Serializer
YamlSerializeAttribute Class
Members See Also Send Feedback
Specify the way to store a property or field of some class or structure. See YamlSerializer for detail.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public sealed class YamlSerializeAttribute : Attribute
Visual Basic (Declaration)
Public NotInheritable Class YamlSerializeAttribute _
    Inherits Attribute
Visual C++
public ref class YamlSerializeAttribute sealed : public Attribute

Inheritance Hierarchy

System..::.Object
System..::.Attribute
System.Yaml.Serialization..::.YamlSerializeAttribute

See Also

YamlSerializeAttribute Members
System.Yaml.Serialization Namespace
System.Yaml.Serialization..::.YamlSerializeAttribute
System.Yaml.Serialization..::.YamlSerializer


YamlSerializeAttribute Members

[image] [image]

YAML Serializer
YamlSerializeAttribute Members
YamlSerializeAttribute Class Constructors Methods Properties See Also Send Feedback

The YamlSerializeAttribute type exposes the following members.

Constructors

Name | Description
YamlSerializeAttribute | Specify the way to store a property or field of some class or structure. See YamlSerializer for detail.

Methods

Name | Description
Equals | (Inherited from Attribute.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Attribute.)
GetType | (Inherited from Object.)
IsDefaultAttribute | (Inherited from Attribute.)
Match | (Inherited from Attribute.)
MemberwiseClone | (Inherited from Object.)
ToString | (Inherited from Object.)

Properties

Name | Description
TypeId | (Inherited from Attribute.)

See Also

YamlSerializeAttribute Class
System.Yaml.Serialization Namespace


YamlSerializeAttribute Constructor

[image]

YAML Serializer
YamlSerializeAttribute Constructor
YamlSerializeAttribute Class See Also Send Feedback
Specify the way to store a property or field of some class or structure. See YamlSerializer for detail.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlSerializeAttribute(
    YamlSerializeMethod SerializeMethod
)
Visual Basic (Declaration)
Public Sub New ( _
    SerializeMethod As YamlSerializeMethod _
)
Visual C++
public:
YamlSerializeAttribute(
    YamlSerializeMethod SerializeMethod
)

Parameters

SerializeMethod
Type: System.Yaml.Serialization..::.YamlSerializeMethod

- Never: The property / field will not be stored.

- Assign: When restored, new object is created by using the parameters in the YAML data and assigned to the property / field. When the property / filed is writeable, this is the default.

- Content: Only valid for a property / field that has a class or struct type. When restored, instead of recreating the whole class or struct, the members are independently restored. When the property / field is not writeable this is the default.

- Binary: Only valid for a property / field that has an array type of a some value type. The content of the array is stored in a binary format encoded in base64 style.

See Also

YamlSerializeAttribute Class
System.Yaml.Serialization Namespace
System.Yaml.Serialization..::.YamlSerializeAttribute
System.Yaml.Serialization..::.YamlSerializer


YamlSerializeAttribute Methods

[image] [image]

YAML Serializer
YamlSerializeAttribute Methods
YamlSerializeAttribute Class See Also Send Feedback

The YamlSerializeAttribute type exposes the following members.

Methods

Name | Description
Equals | (Inherited from Attribute.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Attribute.)
GetType | (Inherited from Object.)
IsDefaultAttribute | (Inherited from Attribute.)
Match | (Inherited from Attribute.)
MemberwiseClone | (Inherited from Object.)
ToString | (Inherited from Object.)

See Also

YamlSerializeAttribute Class
System.Yaml.Serialization Namespace


YamlSerializeAttribute Properties

[image] [image]

YAML Serializer
YamlSerializeAttribute Properties
YamlSerializeAttribute Class See Also Send Feedback

The YamlSerializeAttribute type exposes the following members.

Properties

Name | Description
TypeId | (Inherited from Attribute.)

See Also

YamlSerializeAttribute Class
System.Yaml.Serialization Namespace


YamlSerializeMethod Enumeration

[image]

YAML Serializer
YamlSerializeMethod Enumeration
See Also Send Feedback

Specify the way to store a property or field of some class or structure.

See YamlSerializer for detail.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public enum YamlSerializeMethod
Visual Basic (Declaration)
Public Enumeration YamlSerializeMethod
Visual C++
public enum class YamlSerializeMethod

Members

Member name | Description
Never | The property / field will not be stored.
Assign | When restored, new object is created by using the parameters in the YAML data and assigned to the property / field. When the property / filed is writeable, this is the default.
Content | Only valid for a property / field that has a class or struct type. When restored, instead of recreating the whole class or struct, the members are independently restored. When the property / field is not writeable this is the default.
Binary | Only valid for a property / field that has an array type of a some value type. The content of the array is stored in a binary format encoded in base64 style.

See Also

System.Yaml.Serialization Namespace
System.Yaml.Serialization..::.YamlSerializeAttribute
System.Yaml.Serialization..::.YamlSerializer


YamlSerializer Class

[image]

YAML Serializer
YamlSerializer Class
Members See Also Send Feedback

YamlSerializer class has instance methods Serialize(Object) and Deserialize(String, array<Type>[]()[]), with which C# native objects can be converted into / from YAML text without any preparations.

CopyC#
var serializer = new YamlSerializer();
object obj = GetObjectToSerialize();
string yaml = serializer.Serialize(obj);
object restored = serializer.Deserialize(yaml);
Assert.AreEqual(obj, restored);

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public class YamlSerializer
Visual Basic (Declaration)
Public Class YamlSerializer
Visual C++
public ref class YamlSerializer

Remarks

What kind of objects can be serialized?

YamlSerializer can serialize / deserialize native C# objects of primitive types (bool, char, int,...), enums, built-in non-primitive types (string, decimal), structures, classes and arrays of these types.

On the other hand, it does not deal with IntPtr (which is a primitive type, though) and pointer types (void*, int*, ...) because these types are, by their nature, not persistent.

Classes without a default constructor can be deserialized only when the way of activating an instance is explicitly specified by AddActivator<(Of <(T>)>)(Func<(Of <(Object>)>)).

CopyC#
object obj = new object[]{
    null,
    "abc",
    true,
    1,
    (Byte)1,
    1.0,
    "1",
    new double[]{ 1.1, 2, -3 },
    new string[]{ "def", "ghi", "1" },
    new System.Drawing.Point(1,3),
    new System.Drawing.SolidBrush(Color.Blue)
};

var serializer = new YamlSerializer();
string yaml = serializer.Serialize(obj);
// %YAML 1.2
// ---
// - null
// - abc
// - True
// - 1
// - !System.Byte 1
// - !!float 1
// - "1"
// - !<!System.Double[]%gt; [1.1, 2, -3]
// - !<!System.String[]%gt;
//   - def
//   - ghi
// - !System.Drawing.Point 1, 3
// - !System.Drawing.SolidBrush
//   Color: Blue
// ...

object restored;
try {
    restored = YamlSerializer.Deserialize(yaml)[0];
} catch(MissingMethodException) {
    // default constructor is missing for SolidBrush
}

// Let the library know how to activate an instance of SolidBrush.
YamlNode.DefaultConfig.AddActivator<System.Drawing.SolidBrush>(
    () => new System.Drawing.SolidBrush(Color.Black /* dummy */));

// Then, all the objects can be restored correctly.
restored = serializer.Deserialize(yaml)[0];

A YAML document generated by YamlSerializer always have a %YAML directive and explicit document start ("---") and end ("...") marks. This allows several documents to be written in a single YAML stream.

CopyC#
var yaml = "";
var serializer = new YamlSerializer();
yaml += serializer.Serialize("a");
yaml += serializer.Serialize(1);
yaml += serializer.Serialize(1.1);
// %YAML 1.2
// ---
// a
// ...
// %YAML 1.2
// ---
// 1
// ...
// %YAML 1.2
// ---
// 1.1
// ...

object[] objects = serializer.Deserialize(yaml);
// objects[0] == "a"
// objects[1] == 1
// objects[2] == 1.1

Since a YAML stream can consist of multiple YAML documents as above, Deserialize(String, array<Type>[]()[]) returns an array of Object.

Serializing structures and classes

For structures and classes, by default, all public fields and public properties are serialized. Note that protected / private members are always ignored.

Serialization methods

Readonly value-type members are also ignored because there is no way to assign a new value to them on deserialization, while readonly class-type members are serialized. When deserializing, instead of creating a new object and assigning it to the member, the child members of such class instance are restored independently. Such a deserializing method is refered to YamlSerializeMethod.Content.

On the other hand, when writeable fields/properties are deserialized, new objects are created by using the parameters in the YAML description and assiend to the fields/properties. Such a deserializing method is refered to YamlSerializeMethod.Assign. Writeable properties can be explicitly specified to use YamlSerializeMethod.Content method for deserialization, by adding YamlSerializeAttribute to its definition.

Another type of serializing method is YamlSerializeMethod.Binary. This method is only applicable to an array-type field / property that contains only value-type members.

If serializing method Never is specified, the member is never serialized nor deserialized.

CopyC#
public class Test1
{
    public int PublicProp { get; set; }         // processed (by assign)
    protected int ProtectedProp { get; set; }           // Ignored
    private int PrivateProp { get; set; }               // Ignored
    internal int InternalProp { get; set; }             // Ignored

    public int PublicField;                     // processed (by assign)
    protected int ProtectedField;                       // Ignored
    private int PrivateField;                           // Ignored
    internal int InternalField;                         // Ignored

    public List<string> ClassPropByAssign // processed (by assign)
    { get; set; }

    public int ReadOnlyValueProp { get; private set; }  // Ignored
    public List<string> ReadOnlyClassProp // processed (by content)
    { get; private set; }

    [YamlSerialize(YamlSerializeMethod.Content)]
    public List<string> ClassPropByContent// processed (by content)
    { get; set; }

    public int[] IntArrayField =                // processed (by assign)
       new int[10];

    [YamlSerialize(YamlSerializeMethod.Binary)]
    public int[] IntArrayFieldBinary =          // processed (as binary)
       new int[100];

    [YamlSerialize(YamlSerializeMethod.Never)]
    public int PublicPropHidden;                        // Ignored

    public Test1()
    {
        ClassPropByAssign = new List<string>();
        ReadOnlyClassProp = new List<string>();
        ClassPropByContent = new List<string>();
    }
}

public void TestPropertiesAndFields1()
{
   var test1 = new Test1();
   test1.ClassPropByAssign.Add("abc");
   test1.ReadOnlyClassProp.Add("def");
   test1.ClassPropByContent.Add("ghi");
   var rand = new Random(0);
   for ( int i = 0; i < test1.IntArrayFieldBinary.Length; i++ )
       test1.IntArrayFieldBinary[i] = rand.Next();

   var serializer = new YamlSerializer();
   string yaml = serializer.Serialize(test1);
   // %YAML 1.2
   // ---
   // !YamlSerializerTest.Test1
   // PublicProp: 0
   // ClassPropByAssign:
   //   Capacity: 4
   //   ICollection.Items:
   //     - abc
   // ReadOnlyClassProp:
   //   Capacity: 4
   //   ICollection.Items:
   //     - def
   // ClassPropByContent:
   //   Capacity: 4
   //   ICollection.Items:
   //     - ghi
   // PublicField: 0
   // IntArrayField: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
   // IntArrayFieldBinary: |+2
   //   Gor1XAwenmhGkU5ib9NxR11LXxp1iYlH5LH4c9hImTitWSB9Z78II2UvXSXV99A79fj6UBn3GDzbIbd9
   //   yBDjAyslYm58iGd/NN+tVjuLRCg3cJBo+PWMbIWm9n4AEC0E7LKXWV5HXUNk7I13APEDWFMM/kWTz2EK
   //   s7LzFw2gBjpKugkmQJqIfinpQ1J1yqhhz/XjA3TBxDBsEuwrD+SNevQSqEC+/KRbwgE6D011ACMeyRt0
   //   BOG6ZesRKCtL0YU6tSnLEpgKVBz+R300qD3/W0aZVk+1vHU+auzyGCGUaHCGd6dpRoEhXoIg2m3+AwJX
   //   EJ37T+TA9BuEPJtyGoq+crQMFQtXj1Zriz3HFbReclLvDdVpZlcOHPga/3+3Y509EHZ7UyT7H1xGeJxn
   //   eXPrDDb0Ul04MfZb4UYREOfR3HNzNTUYGRsIPUvHOEW7AaoplIfkVQp19DvGBrBqlP2TZ9atlWUHVdth
   //   7lIBeIh0wiXxoOpCbQ7qVP9GkioQUrMkOcAJaad3exyZaOsXxznFCA==
   // ...
}

Default values of fields and properties

YamlSerializer is aware of System.ComponentModel.DefaultValueAttribute. So, when a member of a structure / class instance has a value that equals to the default value, the member will not be written in the YAML text.

It also checkes for the result of ShouldSerializeXXX method. For instance, just before serializing Font property of some type, bool ShouldSerializeFont() method is called if exists. If the method returns false, Font property will not be written in the YAML text. ShouldSerializeXXX method can be non-public.

CopyC#
using System.ComponentModel;

public class Test2
{
    [DefaultValue(0)]
    public int Default0 = 0;

    [DefaultValue("a")]
    public string Defaulta = "a";

    public int DynamicDefault = 0;

    bool ShouldSerializeDynamicDefault()
    {
        return Default0 != DynamicDefault;
    }
}

public void TestDefaultValue()
{
    var test2 = new Test2();
    var serializer = new YamlSerializer();

    // All properties have defalut values.
    var yaml = serializer.Serialize(test2);
    // %YAML 1.2
    // ---
    // !YamlSerializerTest.Test2 {}
    // ...

    test2.Defaulta = "b";
    yaml = serializer.Serialize(test2);
    // %YAML 1.2
    // ---
    // !YamlSerializerTest.Test2
    // Defaulta: b
    // ...

    test2.Defaulta = "a";
    var yaml = serializer.Serialize(test2);
    // %YAML 1.2
    // ---
    // !YamlSerializerTest.Test2 {}
    // ...

    test2.DynamicDefault = 1;
    yaml = serializer.Serialize(test2);
    // %YAML 1.2
    // ---
    // !YamlSerializerTest.Test2
    // DynamicDefault: 1
    // ...

    test2.Default0 = 1;
    yaml = serializer.Serialize(test2);
    // %YAML 1.2
    // ---
    // !YamlSerializerTest.Test2
    // Default0: 1
    // ...
}

Collection classes

If an object implements ICollection<(Of <(T>)>), IList or IDictionary the child objects are serialized as well its other public members. Pseudproperty ICollection.Items or IDictionary.Entries appears to hold the child objects.

Multitime appearance of a same object

YamlSerializer preserve C# objects' graph structure. Namely, when a same objects are refered to from several points in the object graph, the structure is correctly described in YAML text and restored objects preserve the structure. YamlSerializer can safely manipulate directly / indirectly self refering objects, too.

CopyC#
public class TestClass
{
    public List<TestClass> list =
        new List<TestClass>();
}

public class ChildClass: TestClass
{
}

void RecursiveObjectsTest()
{
    var a = new TestClass();
    var b = new ChildClass();
    a.list.Add(a);
    a.list.Add(a);
    a.list.Add(b);
    a.list.Add(a);
    a.list.Add(b);
    b.list.Add(a);
    var serializer = new YamlSerializer();
    string yaml = serializer.Serialize(a);
    // %YAML 1.2
    // ---
    // &A !TestClass
    // list:
    //   Capacity: 8
    //   ICollection.Items:
    //     - *A
    //     - *A
    //     - &B !ChildClass
    //       list:
    //         Capacity: 4
    //         ICollection.Items:
    //           - *A
    //     - *A
    //     - *B
    // ...

    var restored = (TestClass)serializer.Deserialize(yaml)[0];
    Assert.IsTrue(restored == restored.list[0]);
    Assert.IsTrue(restored == restored.list[1]);
    Assert.IsTrue(restored == restored.list[3]);
    Assert.IsTrue(restored == restored.list[5]);
    Assert.IsTrue(restored.list[2] == restored.list[4]);
}

This is not the case if the object is String. Same instances of String are repeatedly written in a YAML text and restored as different instance of String when deserialized, unless the content of the string is extremely long (longer than 999 chars).

CopyC#
// 1000 chars
string long_str =
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
string short_str = "12345";
object obj = new object[] { long_str, long_str, short_str, short_str };
var serializer = new YamlSerializer();
string yaml = serializer.Serialize(obj);
// %YAML 1.2
// ---
// - &A 01234567890123456789012345678901234567890123456789 ... (snip) ... 789
// - *A
// - "12345"
// - "12345"
// ...

YAML text written / read by YamlSerializer

When serializing, YamlSerializer intelligently uses various YAML 1.2 styles, namely the block style, flow style, explicit mapping and implicit mapping, to maximize readability of the YAML stream.

CopyC#
[Flags]
enum TestEnum: uint
{
    abc = 1,
    あいう = 2
}

public void TestVariousFormats()
{
    var dict = new Dictionary<object, object>();
    dict.Add(new object[] { 1, "a" }, new object());
    object obj = new object[]{
        dict,
        null,
        "abc",
        "1",
        "a ",
        "- a",
        "abc\n",
        "abc\ndef\n",
        "abc\ndef\nghi",
        new double[]{ 1.1, 2, -3, 3.12, 13.2 },
        new int[,] { { 1, 3}, {4, 5}, {10, 1} },
        new string[]{ "jkl", "mno\npqr" },
        new System.Drawing.Point(1,3),
        TestEnum.abc,
        TestEnum.abc | TestEnum.あいう,
    };
    var config = new YamlConfig();
    config.ExplicitlyPreserveLineBreaks = false;
    var serializer = new YamlSerializer(config);
    string yaml = serializer.Serialize(obj);

    // %YAML 1.2
    // ---
    // - !<!System.Collections.Generic.Dictionary%602[[System.Object,...],[System.Object,...]]>
    //   Keys: {}
    //   Values: {}
    //   IDictionary.Entries:
    //     ? - 1
    //       - a
    //     : !System.Object {}
    // - null
    // - abc
    // - "1"
    // - "a "
    // - "- a"
    // - "abc\n"
    // - |+2
    //   abc
    //   def
    // - |-2
    //   abc
    //   def
    //     ghi
    // - !<!System.Double[]> [1.1, 2, -3, 3.12, 13.2]
    // - !<!System.Int32[,]> [[1, 3], [4, 5], [10, 1]]
    // - !<!System.String[]>
    //   - jkl
    //   - |-2
    //     mno
    //     pqr
    // - !System.Drawing.Point 1, 3
    // - !TestEnum abc
    // - !TestEnum abc, あいう
    // ...
}

When deserializing, YamlSerializer accepts any valid YAML 1.2 documents. TAG directives, comments, flow / block styles, implicit / explicit mappings can be freely used to express valid C# objects. Namely, the members of the array can be given eighter in a flow style or in a block style.

By default, YamlSerializer outputs a YAML stream with line break of "\r\n". This can be customized either by setting YamlNode.DefaultConfig.LineBreakForOutput or by giving an instance of YamlConfig to the constructor.

CopyC#
var serializer = new YamlSerializer();
var yaml = serializer.Serialize("abc");
// %YAML 1.2\r\n    // line breaks are explicitly shown in this example
// ---\r\n
// abc\r\n
// ...\r\n

var config = new YamlConfig();
config.LineBreakForOutput = "\n";
serializer = new YamlSerializer(config);
var yaml = serializer.Serialize("abc");
// %YAML 1.2\n
// ---\n
// abc\n
// ...\n

YamlNode.DefaultConfig.LineBreakForOutput = "\n";

var serializer = new YamlSerializer();
serializer = new YamlSerializer();
var yaml = serializer.Serialize("abc");
// %YAML 1.2\n
// ---\n
// abc\n
// ...\n

Line breaks in YAML text

By default, line breaks in multi line values are explicitly presented as escaped style. Although, this makes the resulting YAML stream hard to read, it is necessary to preserve the exact content of the string because the YAML specification requires that a YAML parser must normalize evely line break that is not escaped in a YAML document to be a single line feed "\n" when deserializing.

In order to have the YAML documents easy to be read, set YamlConfig.ExplicitlyPreserveLineBreaks false. Then, the multiline values of will be written in literal style.

Of course, it makes all the line breaks to be normalized into a single line feeds "\n".

CopyC#
var serializer = new YamlSerializer();
var text = "abc\r\n  def\r\nghi\r\n";
// abc
//   def
// ghi

// By default, line breaks explicitly appears in escaped form.
var yaml = serializer.Serialize(text);
// %YAML 1.2
// ---
// "abc\r\n\
// \  def\r\n\
// ghi\r\n"
// ...

// Original line breaks are preserved
var restored = (string)serializer.Deserialize(yaml)[0];
// "abc\r\n  def\r\nghi\r\n"

YamlNode.DefaultConfig.ExplicitlyPreserveLineBreaks = false;

// Literal style is easier to be read.
var yaml = serializer.Serialize(text);
// %YAML 1.2
// ---
// |+2
//   abc
//     def
//   ghi
// ...

// Original line breaks are lost.
var restored = (string)serializer.Deserialize(yaml)[0];
// "abc\n  def\nghi\n"

This library offers two work arounds for this problem, although both of which violates the official behavior of a YAML parser defined in the YAML specification.

One is to set YamlConfig.LineBreakForInput to be "\r\n". Then, the YAML parser normalizes all line breaks into "\r\n" instead of "\n".

The other is to set YamlConfig.NormalizeLineBreaks false. It disables the line break normalization both at output and at input. Namely, the line breaks are written and read as-is when serialized / deserialized.

CopyC#
var serializer = new YamlSerializer();

// text with mixed line breaks
var text = "abc\r  def\nghi\r\n";
// abc\r        // line breaks are explicitly shown in this example
//   def\n
// ghi\r\n

YamlNode.DefaultConfig.ExplicitlyPreserveLineBreaks = false;

// By default, all line breaks are normalized to "\r\n" when serialized.
var yaml = serializer.Serialize(text);
// %YAML 1.2\r\n
// ---\r\n
// |+2\r\n
//   abc\r\n
//     def\r\n
//   ghi\r\n
// ...\r\n

// When deserialized, line breaks are normalized into "\n".
var restored = (string)serializer.Deserialize(yaml)[0];
// "abc\n  def\nghi\n"

// Line breaks are normalized into "\r\n" instead of "\n".
YamlNode.DefaultConfig.LineBreakForInput = "\r\n";
restored = (string)serializer.Deserialize(yaml)[0];
// "abc\r\n  def\r\nghi\r\n"

// Line breaks are written as is,
YamlNode.DefaultConfig.NormalizeLineBreaks = false;
var yaml = serializer.Serialize(text);
// %YAML 1.2\r\n
// ---\r\n
// |+2\r\n
//   abc\r
//     def\n
//   ghi\r\n
// ...\r\n

// and are read as is.
restored = (string)serializer.Deserialize(yaml)[0];
// "abc\r  def\nghi\r\n"

// Note that when the line breaks of YAML stream is changed
// between serialization and deserialization, the original
// line breaks are lost.
yaml = yaml.Replace("\r\n", "\n").Replace("\r", "\n");
restored = (string)serializer.Deserialize(yaml)[0];
// "abc\n  def\nghi\n"

It is repeatedly stated that although these two options are useful in many situation, they makes the YAML parser violate the YAML specification.

Inheritance Hierarchy

System..::.Object
System.Yaml.Serialization..::.YamlSerializer

See Also

YamlSerializer Members
System.Yaml.Serialization Namespace


YamlSerializer Members

[image] [image]

YAML Serializer
YamlSerializer Members
YamlSerializer Class Constructors Methods See Also Send Feedback

The YamlSerializer type exposes the following members.

Constructors

Name | Description
YamlSerializer | Overloaded.

Methods

Name | Description
Deserialize | Overloaded.
DeserializeFromFile | Deserialize C# object(s) from a YAML text in a file named as YamlFileName. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.
Equals | (Inherited from Object.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Object.)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
Serialize | Overloaded.
SerializeToFile | Serialize C# object obj into YAML text and save it into a file named as YamlFileName.
ToString | (Inherited from Object.)

See Also

YamlSerializer Class
System.Yaml.Serialization Namespace


YamlSerializer Constructor

[image] [image]

YAML Serializer
YamlSerializer Constructor
YamlSerializer Class See Also Send Feedback

Overload List

Name | Description
YamlSerializer()()() | Initialize an instance of YamlSerializer that obeys DefaultConfig.
YamlSerializer(YamlConfig) | Initialize an instance of YamlSerializer with custom config.

See Also

YamlSerializer Class
YamlSerializer Members
System.Yaml.Serialization Namespace


YamlSerializer Constructor

[image]

YAML Serializer
YamlSerializer Constructor
YamlSerializer Class See Also Send Feedback
Initialize an instance of YamlSerializer that obeys DefaultConfig.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlSerializer()
Visual Basic (Declaration)
Public Sub New
Visual C++
public:
YamlSerializer()

See Also

YamlSerializer Class
YamlSerializer Overload
System.Yaml.Serialization Namespace


YamlSerializer Constructor (YamlConfig)

[image]

YAML Serializer
YamlSerializer Constructor (YamlConfig)
YamlSerializer Class See Also Send Feedback
Initialize an instance of YamlSerializer with custom config.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public YamlSerializer(
    YamlConfig config
)
Visual Basic (Declaration)
Public Sub New ( _
    config As YamlConfig _
)
Visual C++
public:
YamlSerializer(
    YamlConfig^ config
)

Parameters

config
Type: System.Yaml..::.YamlConfig
Custom YamlConfig to customize serialization.

See Also

YamlSerializer Class
YamlSerializer Overload
System.Yaml.Serialization Namespace


YamlSerializer Methods

[image] [image]

YAML Serializer
YamlSerializer Methods
YamlSerializer Class See Also Send Feedback

The YamlSerializer type exposes the following members.

Methods

Name | Description
Deserialize | Overloaded.
DeserializeFromFile | Deserialize C# object(s) from a YAML text in a file named as YamlFileName. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.
Equals | (Inherited from Object.)
Finalize | (Inherited from Object.)
GetHashCode | (Inherited from Object.)
GetType | (Inherited from Object.)
MemberwiseClone | (Inherited from Object.)
Serialize | Overloaded.
SerializeToFile | Serialize C# object obj into YAML text and save it into a file named as YamlFileName.
ToString | (Inherited from Object.)

See Also

YamlSerializer Class
System.Yaml.Serialization Namespace


Deserialize Method

[image] [image]

YAML Serializer
YamlSerializer..::.Deserialize Method
YamlSerializer Class See Also Send Feedback

Overload List

Name | Description
Deserialize(Stream, array<Type>[]()[]) | Deserialize C# object(s) from a YAML text in a Stream s. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.
Deserialize(TextReader, array<Type>[]()[]) | Deserialize C# object(s) from a YAML text in a TextReader tr. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.
Deserialize(String, array<Type>[]()[]) | Deserialize C# object(s) from a YAML text. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.

See Also

YamlSerializer Class
YamlSerializer Members
System.Yaml.Serialization Namespace


Deserialize Method (Stream, Type[])

[image]

YAML Serializer
YamlSerializer..::.Deserialize Method (Stream, array<Type>[]()[])
YamlSerializer Class See Also Send Feedback
Deserialize C# object(s) from a YAML text in a Stream s. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public Object[] Deserialize(
    Stream s,
    params Type[] types
)
Visual Basic (Declaration)
Public Function Deserialize ( _
    s As Stream, _
    ParamArray types As Type() _
) As Object()
Visual C++
public:
array<Object^>^ Deserialize(
    Stream^ s,
    ... array<Type^>^ types
)

Parameters

s
Type: System.IO..::.Stream
A Stream that contains YAML text from which C# objects are deserialized.
types
Type: array< System..::.Type >[]()[]
Expected type(s) of the root object(s) in the YAML stream.

Return Value

C# object(s) deserialized from YAML text.

See Also

YamlSerializer Class
Deserialize Overload
System.Yaml.Serialization Namespace


Deserialize Method (TextReader, Type[])

[image]

YAML Serializer
YamlSerializer..::.Deserialize Method (TextReader, array<Type>[]()[])
YamlSerializer Class See Also Send Feedback
Deserialize C# object(s) from a YAML text in a TextReader tr. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public Object[] Deserialize(
    TextReader tr,
    params Type[] types
)
Visual Basic (Declaration)
Public Function Deserialize ( _
    tr As TextReader, _
    ParamArray types As Type() _
) As Object()
Visual C++
public:
array<Object^>^ Deserialize(
    TextReader^ tr,
    ... array<Type^>^ types
)

Parameters

tr
Type: System.IO..::.TextReader
A TextReader that contains YAML text from which C# objects are deserialized.
types
Type: array< System..::.Type >[]()[]
Expected type(s) of the root object(s) in the YAML stream.

Return Value

C# object(s) deserialized from YAML text.

See Also

YamlSerializer Class
Deserialize Overload
System.Yaml.Serialization Namespace


Deserialize Method (String, Type[])

[image]

YAML Serializer
YamlSerializer..::.Deserialize Method (String, array<Type>[]()[])
YamlSerializer Class See Also Send Feedback
Deserialize C# object(s) from a YAML text. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public Object[] Deserialize(
    string yaml,
    params Type[] types
)
Visual Basic (Declaration)
Public Function Deserialize ( _
    yaml As String, _
    ParamArray types As Type() _
) As Object()
Visual C++
public:
array<Object^>^ Deserialize(
    String^ yaml,
    ... array<Type^>^ types
)

Parameters

yaml
Type: System..::.String
A YAML text from which C# objects are deserialized.
types
Type: array< System..::.Type >[]()[]
Expected type(s) of the root object(s) in the YAML stream.

Return Value

C# object(s) deserialized from YAML text.

See Also

YamlSerializer Class
Deserialize Overload
System.Yaml.Serialization Namespace


DeserializeFromFile Method

[image]

YAML Serializer
YamlSerializer..::.DeserializeFromFile Method
YamlSerializer Class See Also Send Feedback
Deserialize C# object(s) from a YAML text in a file named as YamlFileName. Since a YAML text can contain multiple YAML documents, each of which represents a C# object, the result is returned as an array of Object.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public Object[] DeserializeFromFile(
    string YamlFileName,
    params Type[] types
)
Visual Basic (Declaration)
Public Function DeserializeFromFile ( _
    YamlFileName As String, _
    ParamArray types As Type() _
) As Object()
Visual C++
public:
array<Object^>^ DeserializeFromFile(
    String^ YamlFileName,
    ... array<Type^>^ types
)

Parameters

YamlFileName
Type: System..::.String
The name of a file that contains YAML text from which C# objects are deserialized.
types
Type: array< System..::.Type >[]()[]
Expected type(s) of the root object(s) in the YAML stream.

Return Value

C# object(s) deserialized from YAML text.

See Also

YamlSerializer Class
System.Yaml.Serialization Namespace


Serialize Method

[image] [image]

YAML Serializer
YamlSerializer..::.Serialize Method
YamlSerializer Class See Also Send Feedback

Overload List

Name | Description
Serialize(Object) | Serialize C# object obj into YAML text.
Serialize(Stream, Object) | Serialize C# object obj into YAML text and write it into a Stream s.
Serialize(TextWriter, Object) | Serialize C# object obj into YAML text and write it into a TextWriter tw.

See Also

YamlSerializer Class
YamlSerializer Members
System.Yaml.Serialization Namespace


Serialize Method (Object)

[image]

YAML Serializer
YamlSerializer..::.Serialize Method (Object)
YamlSerializer Class See Also Send Feedback
Serialize C# object obj into YAML text.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public string Serialize(
    Object obj
)
Visual Basic (Declaration)
Public Function Serialize ( _
    obj As Object _
) As String
Visual C++
public:
String^ Serialize(
    Object^ obj
)

Parameters

obj
Type: System..::.Object
Object to be serialized.

Return Value

YAML text.

See Also

YamlSerializer Class
Serialize Overload
System.Yaml.Serialization Namespace


Serialize Method (Stream, Object)

[image]

YAML Serializer
YamlSerializer..::.Serialize Method (Stream, Object)
YamlSerializer Class See Also Send Feedback
Serialize C# object obj into YAML text and write it into a Stream s.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Serialize(
    Stream s,
    Object obj
)
Visual Basic (Declaration)
Public Sub Serialize ( _
    s As Stream, _
    obj As Object _
)
Visual C++
public:
void Serialize(
    Stream^ s,
    Object^ obj
)

Parameters

s
Type: System.IO..::.Stream
A Stream to which the YAML text is written.
obj
Type: System..::.Object
Object to be serialized.

See Also

YamlSerializer Class
Serialize Overload
System.Yaml.Serialization Namespace


Serialize Method (TextWriter, Object)

[image]

YAML Serializer
YamlSerializer..::.Serialize Method (TextWriter, Object)
YamlSerializer Class See Also Send Feedback
Serialize C# object obj into YAML text and write it into a TextWriter tw.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void Serialize(
    TextWriter tw,
    Object obj
)
Visual Basic (Declaration)
Public Sub Serialize ( _
    tw As TextWriter, _
    obj As Object _
)
Visual C++
public:
void Serialize(
    TextWriter^ tw,
    Object^ obj
)

Parameters

tw
Type: System.IO..::.TextWriter
A TextWriter to which the YAML text is written.
obj
Type: System..::.Object
Object to be serialized.

See Also

YamlSerializer Class
Serialize Overload
System.Yaml.Serialization Namespace


SerializeToFile Method

[image]

YAML Serializer
YamlSerializer..::.SerializeToFile Method
YamlSerializer Class See Also Send Feedback
Serialize C# object obj into YAML text and save it into a file named as YamlFileName.

Namespace: System.Yaml.Serialization
Assembly: YamlSerializer (in YamlSerializer.dll) Version: 0.9.0.1 (0.9.0.1)

Syntax

C#
public void SerializeToFile(
    string YamlFileName,
    Object obj
)
Visual Basic (Declaration)
Public Sub SerializeToFile ( _
    YamlFileName As String, _
    obj As Object _
)
Visual C++
public:
void SerializeToFile(
    String^ YamlFileName,
    Object^ obj
)

Parameters

YamlFileName
Type: System..::.String
A file name to which the YAML text is written.
obj
Type: System..::.Object
Object to be serialized.

See Also

YamlSerializer Class
System.Yaml.Serialization Namespace