Merge pull request #42 from rogernorling/eol-normalization

Normalized line endings
This commit is contained in:
Antoine Aubry 2013-08-25 14:24:58 -07:00
Родитель a05e021e34 289406ad45
Коммит 2383de41ec
52 изменённых файлов: 3506 добавлений и 3397 удалений

Просмотреть файл

@ -19,26 +19,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using YamlDotNet.Core.Tokens;
namespace YamlDotNet.Core
{
/// <summary>
/// Defines constants thar relate to the YAML specification.
/// </summary>
internal static class Constants
{
public static readonly TagDirective[] DefaultTagDirectives = new[]
{
new TagDirective("!", "!"),
new TagDirective("!!", "tag:yaml.org,2002:"),
};
public const int MajorVersion = 1;
public const int MinorVersion = 1;
public const char HandleCharacter = '!';
public const string DefaultHandle = "!";
}
using System;
using YamlDotNet.Core.Tokens;
namespace YamlDotNet.Core
{
/// <summary>
/// Defines constants thar relate to the YAML specification.
/// </summary>
internal static class Constants
{
public static readonly TagDirective[] DefaultTagDirectives = new[]
{
new TagDirective("!", "!"),
new TagDirective("!!", "tag:yaml.org,2002:"),
};
public const int MajorVersion = 1;
public const int MinorVersion = 1;
public const char HandleCharacter = '!';
public const string DefaultHandle = "!";
}
}

Просмотреть файл

@ -764,7 +764,7 @@ namespace YamlDotNet.Core
{
WriteIndicator("...", true, false, false);
WriteIndent();
}
}
state = EmitterState.YAML_EMIT_END_STATE;
}
@ -1861,4 +1861,4 @@ namespace YamlDotNet.Core
}
}
}
}
}

Просмотреть файл

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class AnchorAlias : ParsingEvent, IAnchorAlias
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class DocumentEnd : ParsingEvent, IDocumentEnd
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -30,10 +30,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class DocumentStart : ParsingEvent, IDocumentStart
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -19,68 +19,68 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Defines the event types. This allows for simpler type comparisons.
/// </summary>
internal enum EventType
{
/// <summary>
/// An empty event.
/// </summary>
YAML_NO_EVENT,
/// <summary>
/// A STREAM-START event.
/// </summary>
YAML_STREAM_START_EVENT,
/// <summary>
/// A STREAM-END event.
/// </summary>
YAML_STREAM_END_EVENT,
/// <summary>
/// A DOCUMENT-START event.
/// </summary>
YAML_DOCUMENT_START_EVENT,
/// <summary>
/// A DOCUMENT-END event.
/// </summary>
YAML_DOCUMENT_END_EVENT,
/// <summary>
/// An ALIAS event.
/// </summary>
YAML_ALIAS_EVENT,
/// <summary>
/// A SCALAR event.
/// </summary>
YAML_SCALAR_EVENT,
/// <summary>
/// A SEQUENCE-START event.
/// </summary>
YAML_SEQUENCE_START_EVENT,
/// <summary>
/// A SEQUENCE-END event.
/// </summary>
YAML_SEQUENCE_END_EVENT,
/// <summary>
/// A MAPPING-START event.
/// </summary>
YAML_MAPPING_START_EVENT,
/// <summary>
/// A MAPPING-END event.
/// </summary>
YAML_MAPPING_END_EVENT,
}
}
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Defines the event types. This allows for simpler type comparisons.
/// </summary>
internal enum EventType
{
/// <summary>
/// An empty event.
/// </summary>
YAML_NO_EVENT,
/// <summary>
/// A STREAM-START event.
/// </summary>
YAML_STREAM_START_EVENT,
/// <summary>
/// A STREAM-END event.
/// </summary>
YAML_STREAM_END_EVENT,
/// <summary>
/// A DOCUMENT-START event.
/// </summary>
YAML_DOCUMENT_START_EVENT,
/// <summary>
/// A DOCUMENT-END event.
/// </summary>
YAML_DOCUMENT_END_EVENT,
/// <summary>
/// An ALIAS event.
/// </summary>
YAML_ALIAS_EVENT,
/// <summary>
/// A SCALAR event.
/// </summary>
YAML_SCALAR_EVENT,
/// <summary>
/// A SEQUENCE-START event.
/// </summary>
YAML_SEQUENCE_START_EVENT,
/// <summary>
/// A SEQUENCE-END event.
/// </summary>
YAML_SEQUENCE_END_EVENT,
/// <summary>
/// A MAPPING-START event.
/// </summary>
YAML_MAPPING_START_EVENT,
/// <summary>
/// A MAPPING-END event.
/// </summary>
YAML_MAPPING_END_EVENT,
}
}

Просмотреть файл

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class MappingEnd : ParsingEvent, IMappingEnd
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class MappingStart : NodeEvent, IMappingStart
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -19,28 +19,28 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Specifies the style of a mapping.
/// </summary>
public enum MappingStyle
{
/// <summary>
/// Let the emitter choose the style.
/// </summary>
Any,
/// <summary>
/// The block mapping style.
/// </summary>
Block,
/// <summary>
/// The flow mapping style.
/// </summary>
Flow
}
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Specifies the style of a mapping.
/// </summary>
public enum MappingStyle
{
/// <summary>
/// Let the emitter choose the style.
/// </summary>
Any,
/// <summary>
/// The block mapping style.
/// </summary>
Block,
/// <summary>
/// The flow mapping style.
/// </summary>
Flow
}
}

Просмотреть файл

@ -19,66 +19,66 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Base class for parsing events.
/// </summary>
public abstract class ParsingEvent : IParsingEvent
{
/// <summary>
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Base class for parsing events.
/// </summary>
public abstract class ParsingEvent : IParsingEvent
{
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public abstract int NestingIncrease {
get;
}
/// <summary>
/// Gets the event type, which allows for simpler type comparisons.
/// </summary>
internal abstract EventType Type {
get;
}
private readonly Mark start;
/// <summary>
/// Gets the position in the input stream where the event starts.
/// </summary>
public Mark Start
{
get
{
return start;
}
}
private readonly Mark end;
/// <summary>
/// Gets the position in the input stream where the event ends.
/// </summary>
public Mark End
{
get
{
return end;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="ParsingEvent"/> class.
/// </summary>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
internal ParsingEvent(Mark start, Mark end)
{
this.start = start;
this.end = end;
}
}
/// <summary>
/// Gets the event type, which allows for simpler type comparisons.
/// </summary>
internal abstract EventType Type {
get;
}
private readonly Mark start;
/// <summary>
/// Gets the position in the input stream where the event starts.
/// </summary>
public Mark Start
{
get
{
return start;
}
}
private readonly Mark end;
/// <summary>
/// Gets the position in the input stream where the event ends.
/// </summary>
public Mark End
{
get
{
return end;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="ParsingEvent"/> class.
/// </summary>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
internal ParsingEvent(Mark start, Mark end)
{
this.start = start;
this.end = end;
}
}
}

Просмотреть файл

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class Scalar : NodeEvent, IScalar
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class SequenceEnd : ParsingEvent, ISequenceEnd
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class SequenceStart : NodeEvent, ISequenceStart
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -19,28 +19,28 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Specifies the style of a sequence.
/// </summary>
public enum SequenceStyle
{
/// <summary>
/// Let the emitter choose the style.
/// </summary>
Any,
/// <summary>
/// The block sequence style.
/// </summary>
Block,
/// <summary>
/// The flow sequence style.
/// </summary>
Flow
}
using System;
namespace YamlDotNet.Core.Events
{
/// <summary>
/// Specifies the style of a sequence.
/// </summary>
public enum SequenceStyle
{
/// <summary>
/// Let the emitter choose the style.
/// </summary>
Any,
/// <summary>
/// The block sequence style.
/// </summary>
Block,
/// <summary>
/// The flow sequence style.
/// </summary>
Flow
}
}

Просмотреть файл

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class StreamEnd : ParsingEvent, IStreamEnd
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary>
public class StreamStart : ParsingEvent, IStreamStart
{
/// <summary>
/// <summary>
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// for end events, it will be -1, and for the remaining events, it will be 0.
/// </summary>
public override int NestingIncrease {
get {

Просмотреть файл

@ -19,60 +19,60 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
namespace YamlDotNet.Core
{
/// <summary>
/// Implements an indexer through an IEnumerator&lt;T&gt;.
/// </summary>
public class FakeList<T>
{
private readonly IEnumerator<T> collection;
private int currentIndex = -1;
/// <summary>
/// Initializes a new instance of FakeList&lt;T&gt;.
/// </summary>
/// <param name="collection">The enumerator to use to implement the indexer.</param>
public FakeList(IEnumerator<T> collection)
{
this.collection = collection;
}
/// <summary>
/// Initializes a new instance of FakeList&lt;T&gt;.
/// </summary>
/// <param name="collection">The collection to use to implement the indexer.</param>
public FakeList(IEnumerable<T> collection)
: this(collection.GetEnumerator())
{
}
/// <summary>
/// Gets the element at the specified index.
/// </summary>
/// <remarks>
/// If index is greater or equal than the last used index, this operation is O(index - lastIndex),
/// else this operation is O(index).
/// </remarks>
public T this[int index] {
get {
if(index < currentIndex) {
collection.Reset();
currentIndex = -1;
}
while(currentIndex < index) {
if(!collection.MoveNext()) {
throw new ArgumentOutOfRangeException("index");
}
++currentIndex;
}
return collection.Current;
}
}
}
using System;
using System.Collections.Generic;
namespace YamlDotNet.Core
{
/// <summary>
/// Implements an indexer through an IEnumerator&lt;T&gt;.
/// </summary>
public class FakeList<T>
{
private readonly IEnumerator<T> collection;
private int currentIndex = -1;
/// <summary>
/// Initializes a new instance of FakeList&lt;T&gt;.
/// </summary>
/// <param name="collection">The enumerator to use to implement the indexer.</param>
public FakeList(IEnumerator<T> collection)
{
this.collection = collection;
}
/// <summary>
/// Initializes a new instance of FakeList&lt;T&gt;.
/// </summary>
/// <param name="collection">The collection to use to implement the indexer.</param>
public FakeList(IEnumerable<T> collection)
: this(collection.GetEnumerator())
{
}
/// <summary>
/// Gets the element at the specified index.
/// </summary>
/// <remarks>
/// If index is greater or equal than the last used index, this operation is O(index - lastIndex),
/// else this operation is O(index).
/// </remarks>
public T this[int index] {
get {
if(index < currentIndex) {
collection.Reset();
currentIndex = -1;
}
while(currentIndex < index) {
if(!collection.MoveNext()) {
throw new ArgumentOutOfRangeException("index");
}
++currentIndex;
}
return collection.Current;
}
}
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -19,43 +19,43 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.Core
{
/// <summary>
/// Specifies the style of a YAML scalar.
/// </summary>
public enum ScalarStyle
{
/// <summary>
/// Let the emitter choose the style.
/// </summary>
Any,
/// <summary>
/// The plain scalar style.
/// </summary>
Plain,
/// <summary>
/// The single-quoted scalar style.
/// </summary>
SingleQuoted,
/// <summary>
/// The double-quoted scalar style.
/// </summary>
DoubleQuoted,
/// <summary>
/// The literal scalar style.
/// </summary>
Literal,
/// <summary>
/// The folded scalar style.
/// </summary>
Folded,
}
using System;
namespace YamlDotNet.Core
{
/// <summary>
/// Specifies the style of a YAML scalar.
/// </summary>
public enum ScalarStyle
{
/// <summary>
/// Let the emitter choose the style.
/// </summary>
Any,
/// <summary>
/// The plain scalar style.
/// </summary>
Plain,
/// <summary>
/// The single-quoted scalar style.
/// </summary>
SingleQuoted,
/// <summary>
/// The double-quoted scalar style.
/// </summary>
DoubleQuoted,
/// <summary>
/// The literal scalar style.
/// </summary>
Literal,
/// <summary>
/// The folded scalar style.
/// </summary>
Folded,
}
}

Просмотреть файл

@ -19,54 +19,54 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.Core
{
internal class StringLookAheadBuffer : ILookAheadBuffer
{
private readonly string value;
private int currentIndex;
public int Length {
get {
return value.Length;
}
}
public int Position {
get {
return currentIndex;
}
}
private bool IsOutside(int index) {
return index >= value.Length;
}
public bool EndOfInput {
get {
return IsOutside(currentIndex);
}
}
public StringLookAheadBuffer(string value)
{
this.value = value;
}
public char Peek(int offset)
{
int index = currentIndex + offset;
return IsOutside(index) ? '\0' : value[index];
}
public void Skip(int length)
{
if(length < 0) {
throw new ArgumentOutOfRangeException("length", "The length must be positive.");
}
currentIndex += length;
}
}
using System;
namespace YamlDotNet.Core
{
internal class StringLookAheadBuffer : ILookAheadBuffer
{
private readonly string value;
private int currentIndex;
public int Length {
get {
return value.Length;
}
}
public int Position {
get {
return currentIndex;
}
}
private bool IsOutside(int index) {
return index >= value.Length;
}
public bool EndOfInput {
get {
return IsOutside(currentIndex);
}
}
public StringLookAheadBuffer(string value)
{
this.value = value;
}
public char Peek(int offset)
{
int index = currentIndex + offset;
return IsOutside(index) ? '\0' : value[index];
}
public void Skip(int length)
{
if(length < 0) {
throw new ArgumentOutOfRangeException("length", "The length must be positive.");
}
currentIndex += length;
}
}
}

Просмотреть файл

@ -19,48 +19,48 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.Core.Tokens
{
/// <summary>
/// Represents an alias token.
/// </summary>
public class AnchorAlias : Token
{
private readonly string value;
/// <summary>
/// Gets the value of the alias.
/// </summary>
public string Value
{
get
{
return value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="AnchorAlias"/> class.
/// </summary>
/// <param name="value">The value of the anchor.</param>
public AnchorAlias(string value)
: this(value, Mark.Empty, Mark.Empty)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AnchorAlias"/> class.
/// </summary>
/// <param name="value">The value of the anchor.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
public AnchorAlias(string value, Mark start, Mark end)
: base(start, end)
{
this.value = value;
}
}
using System;
namespace YamlDotNet.Core.Tokens
{
/// <summary>
/// Represents an alias token.
/// </summary>
public class AnchorAlias : Token
{
private readonly string value;
/// <summary>
/// Gets the value of the alias.
/// </summary>
public string Value
{
get
{
return value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="AnchorAlias"/> class.
/// </summary>
/// <param name="value">The value of the anchor.</param>
public AnchorAlias(string value)
: this(value, Mark.Empty, Mark.Empty)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AnchorAlias"/> class.
/// </summary>
/// <param name="value">The value of the anchor.</param>
/// <param name="start">The start position of the event.</param>
/// <param name="end">The end position of the event.</param>
public AnchorAlias(string value, Mark start, Mark end)
: base(start, end)
{
this.value = value;
}
}
}

Просмотреть файл

@ -39,7 +39,7 @@ namespace YamlDotNet.Core
/// <summary>
/// Gets the position in the input stream where the event that originated the exception ends.
/// </summary>
public Mark End { get; private set; }
public Mark End { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="YamlException"/> class.

Просмотреть файл

@ -19,53 +19,53 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Defines the method needed to be able to visit Yaml elements.
/// </summary>
public interface IYamlVisitor
{
/// <summary>
/// Visits a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
void Visit(YamlStream stream);
/// <summary>
/// Visits a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
void Visit(YamlDocument document);
/// <summary>
/// Visits a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited.
/// </param>
void Visit(YamlScalarNode scalar);
/// <summary>
/// Visits a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
void Visit(YamlSequenceNode sequence);
/// <summary>
/// Visits a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
void Visit(YamlMappingNode mapping);
}
using System;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Defines the method needed to be able to visit Yaml elements.
/// </summary>
public interface IYamlVisitor
{
/// <summary>
/// Visits a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
void Visit(YamlStream stream);
/// <summary>
/// Visits a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
void Visit(YamlDocument document);
/// <summary>
/// Visits a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited.
/// </param>
void Visit(YamlScalarNode scalar);
/// <summary>
/// Visits a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
void Visit(YamlSequenceNode sequence);
/// <summary>
/// Visits a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
void Visit(YamlMappingNode mapping);
}
}

Просмотреть файл

@ -1,31 +1,31 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel.Serialization
{
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel.Serialization
{
public sealed class AliasValueDeserializer : IValueDeserializer
{
private readonly IValueDeserializer innerDeserializer;
@ -35,12 +35,12 @@ namespace YamlDotNet.RepresentationModel.Serialization
if (innerDeserializer == null)
{
throw new ArgumentNullException ("innerDeserializer");
}
}
this.innerDeserializer = innerDeserializer;
}
private sealed class AliasState : Dictionary<string, ValuePromise>, IDisposable
private sealed class AliasState : Dictionary<string, ValuePromise>, IDisposable
{
public void Dispose()
{
@ -103,39 +103,39 @@ namespace YamlDotNet.RepresentationModel.Serialization
}
}
}
}
}
public object DeserializeValue (EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
{
object value;
var alias = reader.Allow<AnchorAlias>();
if(alias != null)
{
{
object value;
var alias = reader.Allow<AnchorAlias>();
if(alias != null)
{
var aliasState = state.Get<AliasState>();
ValuePromise valuePromise;
if(!aliasState.TryGetValue(alias.Value, out valuePromise))
ValuePromise valuePromise;
if(!aliasState.TryGetValue(alias.Value, out valuePromise))
{
valuePromise = new ValuePromise(alias);
aliasState.Add(alias.Value, valuePromise);
aliasState.Add(alias.Value, valuePromise);
}
return valuePromise.HasValue ? valuePromise.Value : valuePromise;
}
string anchor = null;
var nodeEvent = reader.Peek<NodeEvent>();
if(nodeEvent != null && !string.IsNullOrEmpty(nodeEvent.Anchor))
{
anchor = nodeEvent.Anchor;
}
return valuePromise.HasValue ? valuePromise.Value : valuePromise;
}
value = innerDeserializer.DeserializeValue(reader, expectedType, state, nestedObjectDeserializer);
if(anchor != null)
{
var aliasState = state.Get<AliasState>();
string anchor = null;
var nodeEvent = reader.Peek<NodeEvent>();
if(nodeEvent != null && !string.IsNullOrEmpty(nodeEvent.Anchor))
{
anchor = nodeEvent.Anchor;
}
value = innerDeserializer.DeserializeValue(reader, expectedType, state, nestedObjectDeserializer);
if(anchor != null)
{
var aliasState = state.Get<AliasState>();
ValuePromise valuePromise;
if (!aliasState.TryGetValue(anchor, out valuePromise))
{
@ -151,10 +151,10 @@ namespace YamlDotNet.RepresentationModel.Serialization
"Anchor '{0}' already defined",
alias.Value
));
}
}
}
}
return value;
}
}
}
}
}

Просмотреть файл

@ -1,22 +1,22 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Antoine Aubry
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Antoine Aubry
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
@ -28,76 +28,76 @@ using YamlDotNet.RepresentationModel.Serialization.NamingConventions;
using YamlDotNet.RepresentationModel.Serialization.NodeDeserializers;
using YamlDotNet.RepresentationModel.Serialization.NodeTypeResolvers;
namespace YamlDotNet.RepresentationModel.Serialization
{
/// <summary>
/// A façade for the YAML library with the standard configuration.
/// </summary>
public sealed class Deserializer
{
private static readonly Dictionary<string, Type> predefinedTagMappings = new Dictionary<string, Type>
{
{ "tag:yaml.org,2002:map", typeof(Dictionary<object, object>) },
{ "tag:yaml.org,2002:bool", typeof(bool) },
{ "tag:yaml.org,2002:float", typeof(double) },
{ "tag:yaml.org,2002:int", typeof(int) },
{ "tag:yaml.org,2002:str", typeof(string) },
{ "tag:yaml.org,2002:timestamp", typeof(DateTime) },
};
private readonly Dictionary<string, Type> tagMappings;
private readonly List<IYamlTypeConverter> converters;
namespace YamlDotNet.RepresentationModel.Serialization
{
/// <summary>
/// A façade for the YAML library with the standard configuration.
/// </summary>
public sealed class Deserializer
{
private static readonly Dictionary<string, Type> predefinedTagMappings = new Dictionary<string, Type>
{
{ "tag:yaml.org,2002:map", typeof(Dictionary<object, object>) },
{ "tag:yaml.org,2002:bool", typeof(bool) },
{ "tag:yaml.org,2002:float", typeof(double) },
{ "tag:yaml.org,2002:int", typeof(int) },
{ "tag:yaml.org,2002:str", typeof(string) },
{ "tag:yaml.org,2002:timestamp", typeof(DateTime) },
};
private readonly Dictionary<string, Type> tagMappings;
private readonly List<IYamlTypeConverter> converters;
private TypeDescriptorProxy typeDescriptor = new TypeDescriptorProxy();
private IValueDeserializer valueDeserializer;
private IValueDeserializer valueDeserializer;
public IList<INodeDeserializer> NodeDeserializers { get; private set; }
public IList<INodeTypeResolver> TypeResolvers { get; private set; }
private class TypeDescriptorProxy : ITypeDescriptor
{
public ITypeDescriptor TypeDescriptor;
public IEnumerable<IPropertyDescriptor> GetProperties(Type type)
{
return TypeDescriptor.GetProperties(type);
}
public IPropertyDescriptor GetProperty(Type type, string name)
{
return TypeDescriptor.GetProperty(type, name);
}
private class TypeDescriptorProxy : ITypeDescriptor
{
public ITypeDescriptor TypeDescriptor;
public IEnumerable<IPropertyDescriptor> GetProperties(Type type)
{
return TypeDescriptor.GetProperties(type);
}
public IPropertyDescriptor GetProperty(Type type, string name)
{
return TypeDescriptor.GetProperty(type, name);
}
}
public Deserializer(IObjectFactory objectFactory = null, INamingConvention namingConvention = null)
{
objectFactory = objectFactory ?? new DefaultObjectFactory();
namingConvention = namingConvention ?? new NullNamingConvention();
typeDescriptor.TypeDescriptor =
new YamlAttributesTypeDescriptor(
new NamingConventionTypeDescriptor(
new ReadableAndWritablePropertiesTypeDescriptor(),
namingConvention
)
);
typeDescriptor.TypeDescriptor =
new YamlAttributesTypeDescriptor(
new NamingConventionTypeDescriptor(
new ReadableAndWritablePropertiesTypeDescriptor(),
namingConvention
)
);
converters = new List<IYamlTypeConverter>();
NodeDeserializers = new List<INodeDeserializer>();
NodeDeserializers.Add(new TypeConverterNodeDeserializer(converters));
NodeDeserializers.Add(new NullNodeDeserializer());
NodeDeserializers.Add(new ScalarNodeDeserializer());
NodeDeserializers.Add(new ArrayNodeDeserializer());
NodeDeserializers.Add(new GenericDictionaryNodeDeserializer(objectFactory));
NodeDeserializers.Add(new NonGenericDictionaryNodeDeserializer(objectFactory));
NodeDeserializers.Add(new GenericCollectionNodeDeserializer(objectFactory));
NodeDeserializers.Add(new NonGenericListNodeDeserializer(objectFactory));
NodeDeserializers.Add(new EnumerableNodeDeserializer());
NodeDeserializers.Add(new ObjectNodeDeserializer(objectFactory, typeDescriptor));
tagMappings = new Dictionary<string, Type>(predefinedTagMappings);
NodeDeserializers = new List<INodeDeserializer>();
NodeDeserializers.Add(new TypeConverterNodeDeserializer(converters));
NodeDeserializers.Add(new NullNodeDeserializer());
NodeDeserializers.Add(new ScalarNodeDeserializer());
NodeDeserializers.Add(new ArrayNodeDeserializer());
NodeDeserializers.Add(new GenericDictionaryNodeDeserializer(objectFactory));
NodeDeserializers.Add(new NonGenericDictionaryNodeDeserializer(objectFactory));
NodeDeserializers.Add(new GenericCollectionNodeDeserializer(objectFactory));
NodeDeserializers.Add(new NonGenericListNodeDeserializer(objectFactory));
NodeDeserializers.Add(new EnumerableNodeDeserializer());
NodeDeserializers.Add(new ObjectNodeDeserializer(objectFactory, typeDescriptor));
tagMappings = new Dictionary<string, Type>(predefinedTagMappings);
TypeResolvers = new List<INodeTypeResolver>();
TypeResolvers.Add(new TagNodeTypeResolver(tagMappings));
TypeResolvers.Add(new TypeNameInTagNodeTypeResolver());
TypeResolvers.Add(new TagNodeTypeResolver(tagMappings));
TypeResolvers.Add(new TypeNameInTagNodeTypeResolver());
TypeResolvers.Add(new DefaultContainersNodeTypeResolver());
valueDeserializer =
@ -106,17 +106,17 @@ namespace YamlDotNet.RepresentationModel.Serialization
NodeDeserializers,
TypeResolvers
)
);
}
public void RegisterTagMapping(string tag, Type type)
{
tagMappings.Add(tag, type);
}
public void RegisterTypeConverter(IYamlTypeConverter typeConverter)
{
converters.Add(typeConverter);
);
}
public void RegisterTagMapping(string tag, Type type)
{
tagMappings.Add(tag, type);
}
public void RegisterTypeConverter(IYamlTypeConverter typeConverter)
{
converters.Add(typeConverter);
}
public T Deserialize<T>(TextReader input)
@ -187,5 +187,5 @@ namespace YamlDotNet.RepresentationModel.Serialization
return result;
}
}
}
}

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using YamlDotNet.Core;

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using YamlDotNet.Core.Events;

Просмотреть файл

@ -1,31 +1,31 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel.Serialization
{
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel.Serialization
{
public interface IValueDeserializer
{
object DeserializeValue(EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer);
}
}
}
}

Просмотреть файл

@ -19,24 +19,24 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Allows an object to customize how it is serialized and deserialized.
/// </summary>
public interface IYamlSerializable
{
/// <summary>
/// Reads this object's state from a YAML parser.
using System;
using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Allows an object to customize how it is serialized and deserialized.
/// </summary>
public interface IYamlSerializable
{
/// <summary>
/// Reads this object's state from a YAML parser.
/// </summary>
void ReadYaml(IParser parser);
/// <summary>
/// Writes this object's state to a YAML emitter.
/// </summary>
void WriteYaml(IEmitter emitter);
}
void ReadYaml(IParser parser);
/// <summary>
/// Writes this object's state to a YAML emitter.
/// </summary>
void WriteYaml(IEmitter emitter);
}
}

Просмотреть файл

@ -26,6 +26,31 @@ using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel.Serialization.NodeDeserializers
{
public sealed class EnumerableNodeDeserializer : INodeDeserializer { bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, out object value) { Type itemsType; if (expectedType == typeof(IEnumerable)) { itemsType = typeof(object); } else { var iEnumerable = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IEnumerable<>)); if (iEnumerable != expectedType) { value = null; return false; } itemsType = iEnumerable.GetGenericArguments()[0]; } var collectionType = typeof(List<>).MakeGenericType(itemsType); value = nestedObjectDeserializer(reader, collectionType); return true; } }
public sealed class EnumerableNodeDeserializer : INodeDeserializer
{
bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, out object value)
{
Type itemsType;
if (expectedType == typeof(IEnumerable))
{
itemsType = typeof(object);
}
else
{
var iEnumerable = ReflectionUtility.GetImplementedGenericInterface(expectedType, typeof(IEnumerable<>));
if (iEnumerable != expectedType)
{
value = null;
return false;
}
itemsType = iEnumerable.GetGenericArguments()[0];
}
var collectionType = typeof(List<>).MakeGenericType(itemsType);
value = nestedObjectDeserializer(reader, collectionType);
return true;
}
}
}

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using YamlDotNet.Core;

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Reflection;

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections;
using YamlDotNet.Core;

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.ComponentModel;
using System.Globalization;

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using YamlDotNet.Core.Events;

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using YamlDotNet.Core.Events;

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using YamlDotNet.Core.Events;

Просмотреть файл

@ -1,32 +1,32 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel.Serialization
{
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel.Serialization
{
public sealed class NodeValueDeserializer : IValueDeserializer
{
private readonly IList<INodeDeserializer> deserializers;
@ -83,5 +83,5 @@ namespace YamlDotNet.RepresentationModel.Serialization
}
return currentType;
}
}
}
}
}

Просмотреть файл

@ -1,48 +1,48 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) 2013 Antoine Aubry
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
namespace YamlDotNet.RepresentationModel.Serialization
{
using System.Linq;
namespace YamlDotNet.RepresentationModel.Serialization
{
/// <summary>
/// A generic container that is preserved during the entire deserialization process.
/// Any disposable object added to this collecion will be disposed when this object is disposed.
/// </summary>
public sealed class SerializerState : IDisposable
{
private readonly IDictionary<Type, object> items = new Dictionary<Type, object>();
public T Get<T>()
where T : class, new()
{
object value;
if(!items.TryGetValue(typeof(T), out value))
{
value = new T();
items.Add(typeof(T), value);
}
return (T)value;
/// </summary>
public sealed class SerializerState : IDisposable
{
private readonly IDictionary<Type, object> items = new Dictionary<Type, object>();
public T Get<T>()
where T : class, new()
{
object value;
if(!items.TryGetValue(typeof(T), out value))
{
value = new T();
items.Add(typeof(T), value);
}
return (T)value;
}
public void Dispose()
@ -52,5 +52,5 @@ namespace YamlDotNet.RepresentationModel.Serialization
disposable.Dispose();
}
}
}
}
}
}

Просмотреть файл

@ -67,7 +67,7 @@ namespace YamlDotNet.RepresentationModel.Serialization
depth += parser.Current.NestingIncrease;
} while (depth > 0);
Debug.Assert(depth == 0);
Debug.Assert(depth == 0);
}
/// <summary>

Просмотреть файл

@ -1,58 +1,58 @@
using System;
using System.Text.RegularExpressions;
namespace YamlDotNet.RepresentationModel.Serialization
{
/// <summary>
/// Various string extension methods
/// </summary>
internal static class StringExtensions
{
namespace YamlDotNet.RepresentationModel.Serialization
{
/// <summary>
/// Various string extension methods
/// </summary>
internal static class StringExtensions
{
private static string ToCamelOrPascalCase(string str, Func<char, char> firstLetterTransform)
{
var text = Regex.Replace(str, "([_\\-])(?<char>[a-z])", match => match.Groups["char"].Value.ToUpperInvariant(), RegexOptions.IgnoreCase);
return firstLetterTransform(text[0]) + text.Substring(1);
}
/// <summary>
/// Convert the string with underscores (this_is_a_test) or hyphens (this-is-a-test) to
/// camel case (thisIsATest). Camel case is the same as Pascal case, except the first letter
/// is lowercase.
/// </summary>
/// <param name="str">String to convert</param>
/// <returns>Converted string</returns>
public static string ToCamelCase(this string str)
{
return ToCamelOrPascalCase(str, char.ToLowerInvariant);
}
/// <summary>
/// Convert the string with underscores (this_is_a_test) or hyphens (this-is-a-test) to
/// pascal case (ThisIsATest). Pascal case is the same as camel case, except the first letter
/// is uppercase.
/// </summary>
/// <param name="str">String to convert</param>
/// <returns>Converted string</returns>
public static string ToPascalCase(this string str)
{
/// <summary>
/// Convert the string with underscores (this_is_a_test) or hyphens (this-is-a-test) to
/// camel case (thisIsATest). Camel case is the same as Pascal case, except the first letter
/// is lowercase.
/// </summary>
/// <param name="str">String to convert</param>
/// <returns>Converted string</returns>
public static string ToCamelCase(this string str)
{
return ToCamelOrPascalCase(str, char.ToLowerInvariant);
}
/// <summary>
/// Convert the string with underscores (this_is_a_test) or hyphens (this-is-a-test) to
/// pascal case (ThisIsATest). Pascal case is the same as camel case, except the first letter
/// is uppercase.
/// </summary>
/// <param name="str">String to convert</param>
/// <returns>Converted string</returns>
public static string ToPascalCase(this string str)
{
return ToCamelOrPascalCase(str, char.ToUpperInvariant);
}
/// <summary>
/// Convert the string from camelcase (thisIsATest) to a hyphenated (this-is-a-test) or
/// underscored (this_is_a_test) string
/// </summary>
/// <param name="str">String to convert</param>
/// <param name="separator">Separator to use between segments</param>
/// <returns>Converted string</returns>
public static string FromCamelCase(this string str, string separator)
{
// Ensure first letter is always lowercase
str = char.ToLower(str[0]) + str.Substring(1);
str = Regex.Replace(str.ToCamelCase(), "(?<char>[A-Z])", match => separator + match.Groups["char"].Value.ToLowerInvariant());
return str;
}
}
}
}
/// <summary>
/// Convert the string from camelcase (thisIsATest) to a hyphenated (this-is-a-test) or
/// underscored (this_is_a_test) string
/// </summary>
/// <param name="str">String to convert</param>
/// <param name="separator">Separator to use between segments</param>
/// <returns>Converted string</returns>
public static string FromCamelCase(this string str, string separator)
{
// Ensure first letter is always lowercase
str = char.ToLower(str[0]) + str.Substring(1);
str = Regex.Replace(str.ToCamelCase(), "(?<char>[A-Z])", match => separator + match.Groups["char"].Value.ToLowerInvariant());
return str;
}
}
}

Просмотреть файл

@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;

Просмотреть файл

@ -51,7 +51,7 @@ namespace YamlDotNet.RepresentationModel
/// <summary>
/// Gets the position in the input stream where the event that originated the node ends.
/// </summary>
public Mark End { get; private set; }
public Mark End { get; private set; }
/// <summary>
/// Loads the specified event.

Просмотреть файл

@ -19,204 +19,204 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Abstract implementation of <see cref="IYamlVisitor"/> that knows how to walk a complete Yaml object model.
/// </summary>
public abstract class YamlVisitor : IYamlVisitor {
/// <summary>
/// Called when this object is visiting a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
protected virtual void Visit (YamlStream stream)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that has been visited.
/// </param>
protected virtual void Visited (YamlStream stream)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
protected virtual void Visit (YamlDocument document) {
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that has been visited.
/// </param>
protected virtual void Visited (YamlDocument document)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited.
/// </param>
protected virtual void Visit (YamlScalarNode scalar)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that has been visited.
/// </param>
protected virtual void Visited (YamlScalarNode scalar)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
protected virtual void Visit (YamlSequenceNode sequence)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that has been visited.
/// </param>
protected virtual void Visited (YamlSequenceNode sequence)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
protected virtual void Visit (YamlMappingNode mapping)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that has been visited.
/// </param>
protected virtual void Visited (YamlMappingNode mapping)
{
// Do nothing.
}
/// <summary>
/// Visits every child of a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlStream stream) {
foreach (var document in stream.Documents) {
document.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlDocument document) {
if(document.RootNode != null) {
document.RootNode.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlSequenceNode sequence) {
foreach (var node in sequence.Children) {
node.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlMappingNode mapping) {
foreach (var pair in mapping.Children) {
pair.Key.Accept(this);
pair.Value.Accept(this);
}
}
void IYamlVisitor.Visit (YamlStream stream)
{
Visit(stream);
VisitChildren(stream);
Visited(stream);
}
void IYamlVisitor.Visit (YamlDocument document)
{
Visit(document);
VisitChildren(document);
Visited(document);
}
void IYamlVisitor.Visit (YamlScalarNode scalar)
{
Visit(scalar);
Visited(scalar);
}
void IYamlVisitor.Visit (YamlSequenceNode sequence)
{
Visit(sequence);
VisitChildren(sequence);
Visited(sequence);
}
void IYamlVisitor.Visit (YamlMappingNode mapping)
{
Visit(mapping);
VisitChildren(mapping);
Visited(mapping);
}
}
using System;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Abstract implementation of <see cref="IYamlVisitor"/> that knows how to walk a complete Yaml object model.
/// </summary>
public abstract class YamlVisitor : IYamlVisitor {
/// <summary>
/// Called when this object is visiting a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
protected virtual void Visit (YamlStream stream)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that has been visited.
/// </param>
protected virtual void Visited (YamlStream stream)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
protected virtual void Visit (YamlDocument document) {
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that has been visited.
/// </param>
protected virtual void Visited (YamlDocument document)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited.
/// </param>
protected virtual void Visit (YamlScalarNode scalar)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that has been visited.
/// </param>
protected virtual void Visited (YamlScalarNode scalar)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
protected virtual void Visit (YamlSequenceNode sequence)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that has been visited.
/// </param>
protected virtual void Visited (YamlSequenceNode sequence)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
protected virtual void Visit (YamlMappingNode mapping)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that has been visited.
/// </param>
protected virtual void Visited (YamlMappingNode mapping)
{
// Do nothing.
}
/// <summary>
/// Visits every child of a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlStream stream) {
foreach (var document in stream.Documents) {
document.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlDocument document) {
if(document.RootNode != null) {
document.RootNode.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlSequenceNode sequence) {
foreach (var node in sequence.Children) {
node.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlMappingNode mapping) {
foreach (var pair in mapping.Children) {
pair.Key.Accept(this);
pair.Value.Accept(this);
}
}
void IYamlVisitor.Visit (YamlStream stream)
{
Visit(stream);
VisitChildren(stream);
Visited(stream);
}
void IYamlVisitor.Visit (YamlDocument document)
{
Visit(document);
VisitChildren(document);
Visited(document);
}
void IYamlVisitor.Visit (YamlScalarNode scalar)
{
Visit(scalar);
Visited(scalar);
}
void IYamlVisitor.Visit (YamlSequenceNode sequence)
{
Visit(sequence);
VisitChildren(sequence);
Visited(sequence);
}
void IYamlVisitor.Visit (YamlMappingNode mapping)
{
Visit(mapping);
VisitChildren(mapping);
Visited(mapping);
}
}
}

Просмотреть файл

@ -1,90 +1,90 @@
using System;
using System.IO;
using YamlDotNet.RepresentationModel.Serialization;
namespace YamlDotNet.Samples
{
public class DeserializeObjectGraph
{
public void Run(string[] args)
{
// Setup the input
var input = new StringReader(_document);
using System;
using System.IO;
using YamlDotNet.RepresentationModel.Serialization;
namespace YamlDotNet.Samples
{
public class DeserializeObjectGraph
{
public void Run(string[] args)
{
// Setup the input
var input = new StringReader(_document);
var deserializer = new Deserializer();
var order = (Order)deserializer.Deserialize(input, typeof(Order));
Console.WriteLine("Receipt: {0}", order.Receipt);
Console.WriteLine("Customer: {0} {1}", order.Customer.Given, order.Customer.Family);
}
private class Order
{
public string Receipt { get; set; }
public DateTime Date { get; set; }
public Customer Customer { get; set; }
public Item[] Items { get; set; }
public Address BillTo { get; set; }
public Address ShipTo { get; set; }
public string SpecialDelivery { get; set; }
}
private class Customer
{
public string Given { get; set; }
public string Family { get; set; }
}
public class Item
{
public string PartNo { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
[YamlAlias("descrip")]
public string Description { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
}
private const string _document = @"---
receipt: Oz-Ware Purchase Invoice
date: 2007-08-06
customer:
given: Dorothy
family: Gale
items:
- part_no: A4786
descrip: Water Bucket (Filled)
price: 1.47
quantity: 4
- part_no: E1628
descrip: High Heeled ""Ruby"" Slippers
price: 100.27
quantity: 1
bill-to: &id001
street: |
123 Tornado Alley
Suite 16
city: East Westville
state: KS
ship-to: *id001
specialDelivery: >
Follow the Yellow Brick
Road to the Emerald City.
Pay no attention to the
man behind the curtain.
...";
}
}
var order = (Order)deserializer.Deserialize(input, typeof(Order));
Console.WriteLine("Receipt: {0}", order.Receipt);
Console.WriteLine("Customer: {0} {1}", order.Customer.Given, order.Customer.Family);
}
private class Order
{
public string Receipt { get; set; }
public DateTime Date { get; set; }
public Customer Customer { get; set; }
public Item[] Items { get; set; }
public Address BillTo { get; set; }
public Address ShipTo { get; set; }
public string SpecialDelivery { get; set; }
}
private class Customer
{
public string Given { get; set; }
public string Family { get; set; }
}
public class Item
{
public string PartNo { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
[YamlAlias("descrip")]
public string Description { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
}
private const string _document = @"---
receipt: Oz-Ware Purchase Invoice
date: 2007-08-06
customer:
given: Dorothy
family: Gale
items:
- part_no: A4786
descrip: Water Bucket (Filled)
price: 1.47
quantity: 4
- part_no: E1628
descrip: High Heeled ""Ruby"" Slippers
price: 100.27
quantity: 1
bill-to: &id001
street: |
123 Tornado Alley
Suite 16
city: East Westville
state: KS
ship-to: *id001
specialDelivery: >
Follow the Yellow Brick
Road to the Emerald City.
Pay no attention to the
man behind the curtain.
...";
}
}

Просмотреть файл

@ -9,7 +9,7 @@
// so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

Просмотреть файл

@ -27,151 +27,235 @@ using Xunit;
using Xunit.Extensions;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.RepresentationModel;
namespace YamlDotNet.UnitTests
{
public class EmitterTests : YamlTest
{
private void ParseAndEmit(string name) {
string testText = YamlFile(name).ReadToEnd();
IParser parser = new Parser(new StringReader(testText));
using(StringWriter output = new StringWriter()) {
IEmitter emitter = new Emitter(output, 2, int.MaxValue, false);
while(parser.MoveNext()) {
//Console.WriteLine(parser.Current.GetType().Name);
Console.Error.WriteLine(parser.Current);
emitter.Emit(parser.Current);
}
string result = output.ToString();
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine(testText);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine(result);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
/*
Parser resultParser = new Parser(new StringReader(result));
while(resultParser.MoveNext()) {
Console.WriteLine(resultParser.Current.GetType().Name);
}
*/
/*
if(testText != result) {
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine("Expected:");
Console.WriteLine();
Console.WriteLine(testText);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine("Result:");
Console.WriteLine();
Console.WriteLine(result);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
}
Assert.Equal(testText, result);
*/
}
}
[Fact]
public void EmitExample1()
{
ParseAndEmit("test1.yaml");
}
[Fact]
public void EmitExample2()
{
ParseAndEmit("test2.yaml");
}
[Fact]
public void EmitExample3()
{
ParseAndEmit("test3.yaml");
}
[Fact]
public void EmitExample4()
{
ParseAndEmit("test4.yaml");
}
[Fact]
public void EmitExample5()
{
ParseAndEmit("test5.yaml");
}
[Fact]
public void EmitExample6()
{
ParseAndEmit("test6.yaml");
}
[Fact]
public void EmitExample7()
{
ParseAndEmit("test7.yaml");
}
[Fact]
public void EmitExample8()
{
ParseAndEmit("test8.yaml");
}
[Fact]
public void EmitExample9()
{
ParseAndEmit("test9.yaml");
}
[Fact]
public void EmitExample10()
{
ParseAndEmit("test10.yaml");
}
[Fact]
public void EmitExample11()
{
ParseAndEmit("test11.yaml");
}
[Fact]
public void EmitExample12()
{
ParseAndEmit("test12.yaml");
}
[Fact]
public void EmitExample13()
{
ParseAndEmit("test13.yaml");
}
[Fact]
public void EmitExample14()
{
ParseAndEmit("test14.yaml");
using YamlDotNet.RepresentationModel;
namespace YamlDotNet.UnitTests
{
public class EmitterTests : YamlTest
{
private void ParseAndEmit(string name) {
string testText = YamlFile(name).ReadToEnd();
IParser parser = new Parser(new StringReader(testText));
using(StringWriter output = new StringWriter()) {
IEmitter emitter = new Emitter(output, 2, int.MaxValue, false);
while(parser.MoveNext()) {
//Console.WriteLine(parser.Current.GetType().Name);
Console.Error.WriteLine(parser.Current);
emitter.Emit(parser.Current);
}
string result = output.ToString();
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine(testText);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine(result);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
/*
Parser resultParser = new Parser(new StringReader(result));
while(resultParser.MoveNext()) {
Console.WriteLine(resultParser.Current.GetType().Name);
}
*/
/*
if(testText != result) {
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine("Expected:");
Console.WriteLine();
Console.WriteLine(testText);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
Console.WriteLine("Result:");
Console.WriteLine();
Console.WriteLine(result);
Console.WriteLine();
Console.WriteLine("------------------------------");
Console.WriteLine();
}
Assert.Equal(testText, result);
*/
}
}
[Fact]
public void EmitExample1()
{
ParseAndEmit("test1.yaml");
}
[Fact]
public void EmitExample2()
{
ParseAndEmit("test2.yaml");
}
[Fact]
public void EmitExample3()
{
ParseAndEmit("test3.yaml");
}
[Fact]
public void EmitExample4()
{
ParseAndEmit("test4.yaml");
}
[Fact]
public void EmitExample5()
{
ParseAndEmit("test5.yaml");
}
[Fact]
public void EmitExample6()
{
ParseAndEmit("test6.yaml");
}
[Fact]
public void EmitExample7()
{
ParseAndEmit("test7.yaml");
}
[Fact]
public void EmitExample8()
{
ParseAndEmit("test8.yaml");
}
[Fact]
public void EmitExample9()
{
ParseAndEmit("test9.yaml");
}
[Fact]
public void EmitExample10()
{
ParseAndEmit("test10.yaml");
}
[Fact]
public void EmitExample11()
{
ParseAndEmit("test11.yaml");
}
[Fact]
public void EmitExample12()
{
ParseAndEmit("test12.yaml");
}
[Fact]
public void EmitExample13()
{
ParseAndEmit("test13.yaml");
}
[Fact]
public void EmitExample14()
{
ParseAndEmit("test14.yaml");
}
[Fact]
public void EmitExample1()
{
ParseAndEmit("test1.yaml");
}
[Fact]
public void EmitExample2()
{
ParseAndEmit("test2.yaml");
}
[Fact]
public void EmitExample3()
{
ParseAndEmit("test3.yaml");
}
[Fact]
public void EmitExample4()
{
ParseAndEmit("test4.yaml");
}
[Fact]
public void EmitExample5()
{
ParseAndEmit("test5.yaml");
}
[Fact]
public void EmitExample6()
{
ParseAndEmit("test6.yaml");
}
[Fact]
public void EmitExample7()
{
ParseAndEmit("test7.yaml");
}
[Fact]
public void EmitExample8()
{
ParseAndEmit("test8.yaml");
}
[Fact]
public void EmitExample9()
{
ParseAndEmit("test9.yaml");
}
[Fact]
public void EmitExample10()
{
ParseAndEmit("test10.yaml");
}
[Fact]
public void EmitExample11()
{
ParseAndEmit("test11.yaml");
}
[Fact]
public void EmitExample12()
{
ParseAndEmit("test12.yaml");
}
[Fact]
public void EmitExample13()
{
ParseAndEmit("test13.yaml");
}
[Fact]
public void EmitExample14()
{
ParseAndEmit("test14.yaml");
}
private string EmitScalar(Scalar scalar)
@ -270,5 +354,5 @@ namespace YamlDotNet.UnitTests
Assert.Equal(input, value.Value);
}
}
}
}

Просмотреть файл

@ -19,100 +19,100 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using YamlDotNet.Core;
using Xunit;
namespace YamlDotNet.UnitTests
{
public class InsertionQueueTests
{
[Fact]
public void QueueWorks() {
InsertionQueue<int> queue = new InsertionQueue<int>();
for (int i = 0; i < 100; ++i) {
queue.Enqueue(i);
}
for (int i = 0; i < 100; ++i) {
Assert.Equal(i, queue.Dequeue());
}
for (int i = 0; i < 50; ++i) {
queue.Enqueue(i);
}
for (int i = 0; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue());
}
for (int i = 50; i < 100; ++i) {
queue.Enqueue(i);
}
for (int i = 10; i < 100; ++i) {
Assert.Equal(i, queue.Dequeue());
}
}
[Fact]
public void InsertWorks() {
InsertionQueue<int> queue = new InsertionQueue<int>();
for(int j = 0; j < 2; ++j) {
for (int i = 0; i < 10; ++i) {
queue.Enqueue(i);
}
queue.Insert(5, 99);
for (int i = 0; i < 5; ++i) {
Assert.Equal(i, queue.Dequeue());
}
Assert.Equal(99, queue.Dequeue());
for (int i = 5; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue());
}
}
for (int i = 0; i < 5; ++i) {
queue.Enqueue(i);
queue.Dequeue();
}
for (int i = 0; i < 20; ++i) {
queue.Enqueue(i);
}
queue.Insert(5, 99);
for (int i = 0; i < 5; ++i) {
Assert.Equal(i, queue.Dequeue());
}
Assert.Equal(99, queue.Dequeue());
for (int i = 5; i < 20; ++i) {
Assert.Equal(i, queue.Dequeue());
}
}
[Fact]
public void Dequeue_ThrowsExceptionWhenEmpty() {
InsertionQueue<int> queue = new InsertionQueue<int>();
for (int i = 0; i < 10; ++i) {
queue.Enqueue(i);
}
for (int i = 0; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue());
}
Assert.Throws<InvalidOperationException>(() => queue.Dequeue());
}
}
using System;
using YamlDotNet.Core;
using Xunit;
namespace YamlDotNet.UnitTests
{
public class InsertionQueueTests
{
[Fact]
public void QueueWorks() {
InsertionQueue<int> queue = new InsertionQueue<int>();
for (int i = 0; i < 100; ++i) {
queue.Enqueue(i);
}
for (int i = 0; i < 100; ++i) {
Assert.Equal(i, queue.Dequeue());
}
for (int i = 0; i < 50; ++i) {
queue.Enqueue(i);
}
for (int i = 0; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue());
}
for (int i = 50; i < 100; ++i) {
queue.Enqueue(i);
}
for (int i = 10; i < 100; ++i) {
Assert.Equal(i, queue.Dequeue());
}
}
[Fact]
public void InsertWorks() {
InsertionQueue<int> queue = new InsertionQueue<int>();
for(int j = 0; j < 2; ++j) {
for (int i = 0; i < 10; ++i) {
queue.Enqueue(i);
}
queue.Insert(5, 99);
for (int i = 0; i < 5; ++i) {
Assert.Equal(i, queue.Dequeue());
}
Assert.Equal(99, queue.Dequeue());
for (int i = 5; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue());
}
}
for (int i = 0; i < 5; ++i) {
queue.Enqueue(i);
queue.Dequeue();
}
for (int i = 0; i < 20; ++i) {
queue.Enqueue(i);
}
queue.Insert(5, 99);
for (int i = 0; i < 5; ++i) {
Assert.Equal(i, queue.Dequeue());
}
Assert.Equal(99, queue.Dequeue());
for (int i = 5; i < 20; ++i) {
Assert.Equal(i, queue.Dequeue());
}
}
[Fact]
public void Dequeue_ThrowsExceptionWhenEmpty() {
InsertionQueue<int> queue = new InsertionQueue<int>();
for (int i = 0; i < 10; ++i) {
queue.Enqueue(i);
}
for (int i = 0; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue());
}
Assert.Throws<InvalidOperationException>(() => queue.Dequeue());
}
}
}

Просмотреть файл

@ -19,74 +19,74 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.IO;
using System.Reflection;
using Xunit;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.UnitTests
{
public class LookAheadBufferTests
{
private static LookAheadBuffer CreateBuffer(string text, int capacity) {
return new LookAheadBuffer(new StringReader(text), capacity);
}
[Fact]
public void ReadingWorks()
{
LookAheadBuffer buffer = CreateBuffer("abcdefghi", 4);
FieldInfo count = buffer.GetType().GetField("count", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.NotNull(count);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('a', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
Assert.Equal('b', buffer.Peek(1));
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('c', buffer.Peek(2));
Assert.Equal(3, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('b', buffer.Peek(0));
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('c', buffer.Peek(1));
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('d', buffer.Peek(2));
Assert.Equal(3, count.GetValue(buffer));
Assert.Equal('e', buffer.Peek(3));
Assert.Equal(4, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(3, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(2, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('f', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('g', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('h', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('i', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.False(buffer.EndOfInput);
Assert.Equal('\0', buffer.Peek(0));
Assert.True(buffer.EndOfInput);
Assert.Equal(0, count.GetValue(buffer));
}
}
using System;
using System.IO;
using System.Reflection;
using Xunit;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.UnitTests
{
public class LookAheadBufferTests
{
private static LookAheadBuffer CreateBuffer(string text, int capacity) {
return new LookAheadBuffer(new StringReader(text), capacity);
}
[Fact]
public void ReadingWorks()
{
LookAheadBuffer buffer = CreateBuffer("abcdefghi", 4);
FieldInfo count = buffer.GetType().GetField("count", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.NotNull(count);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('a', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
Assert.Equal('b', buffer.Peek(1));
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('c', buffer.Peek(2));
Assert.Equal(3, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('b', buffer.Peek(0));
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('c', buffer.Peek(1));
Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('d', buffer.Peek(2));
Assert.Equal(3, count.GetValue(buffer));
Assert.Equal('e', buffer.Peek(3));
Assert.Equal(4, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(3, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(2, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('f', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('g', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('h', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('i', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer));
Assert.False(buffer.EndOfInput);
Assert.Equal('\0', buffer.Peek(0));
Assert.True(buffer.EndOfInput);
Assert.Equal(0, count.GetValue(buffer));
}
}
}

Просмотреть файл

@ -1,43 +1,43 @@
using Xunit;
using Xunit.Extensions;
using Xunit;
using Xunit.Extensions;
using YamlDotNet.RepresentationModel;
using YamlDotNet.RepresentationModel.Serialization;
using YamlDotNet.RepresentationModel.Serialization.NamingConventions;
namespace YamlDotNet.UnitTests.RepresentationModel
{
public class NamingConventionTests
{
[Theory]
[InlineData("test", "test")]
[InlineData("thisIsATest", "this-is-a-test")]
[InlineData("thisIsATest", "this_is_a_test")]
[InlineData("thisIsATest", "ThisIsATest")]
public void TestCamelCase(string expected, string input)
using YamlDotNet.RepresentationModel.Serialization.NamingConventions;
namespace YamlDotNet.UnitTests.RepresentationModel
{
public class NamingConventionTests
{
[Theory]
[InlineData("test", "test")]
[InlineData("thisIsATest", "this-is-a-test")]
[InlineData("thisIsATest", "this_is_a_test")]
[InlineData("thisIsATest", "ThisIsATest")]
public void TestCamelCase(string expected, string input)
{
var sut = new CamelCaseNamingConvention();
Assert.Equal(expected, sut.Apply(input));
}
[Theory]
[InlineData("Test", "test")]
[InlineData("ThisIsATest", "this-is-a-test")]
[InlineData("ThisIsATest", "this_is_a_test")]
[InlineData("ThisIsATest", "thisIsATest")]
public void TestPascalCase(string expected, string input)
Assert.Equal(expected, sut.Apply(input));
}
[Theory]
[InlineData("Test", "test")]
[InlineData("ThisIsATest", "this-is-a-test")]
[InlineData("ThisIsATest", "this_is_a_test")]
[InlineData("ThisIsATest", "thisIsATest")]
public void TestPascalCase(string expected, string input)
{
var sut = new PascalCaseNamingConvention();
Assert.Equal(expected, sut.Apply(input));
}
[Theory]
[InlineData("test", "test")]
[InlineData("this-is-a-test", "thisIsATest")]
[InlineData("this-is-a-test", "this-is-a-test")]
public void TestHyphenated(string expected, string input)
Assert.Equal(expected, sut.Apply(input));
}
[Theory]
[InlineData("test", "test")]
[InlineData("this-is-a-test", "thisIsATest")]
[InlineData("this-is-a-test", "this-is-a-test")]
public void TestHyphenated(string expected, string input)
{
var sut = new HyphenatedNamingConvention();
Assert.Equal(expected, sut.Apply(input));
Assert.Equal(expected, sut.Apply(input));
}
[Theory]
@ -49,5 +49,5 @@ namespace YamlDotNet.UnitTests.RepresentationModel
var sut = new UnderscoredNamingConvention();
Assert.Equal(expected, sut.Apply(input));
}
}
}
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -20,7 +20,7 @@
// SOFTWARE.
using Microsoft.VisualStudio.Utilities;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition;
namespace YamlDotNetEditor
{