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

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

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

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

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class AnchorAlias : ParsingEvent, IAnchorAlias public class AnchorAlias : ParsingEvent, IAnchorAlias
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class DocumentEnd : ParsingEvent, IDocumentEnd public class DocumentEnd : ParsingEvent, IDocumentEnd
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

@ -30,10 +30,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class DocumentStart : ParsingEvent, IDocumentStart public class DocumentStart : ParsingEvent, IDocumentStart
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

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

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

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class MappingEnd : ParsingEvent, IMappingEnd public class MappingEnd : ParsingEvent, IMappingEnd
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class MappingStart : NodeEvent, IMappingStart public class MappingStart : NodeEvent, IMappingStart
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

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

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

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

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

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class Scalar : NodeEvent, IScalar public class Scalar : NodeEvent, IScalar
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class SequenceEnd : ParsingEvent, ISequenceEnd public class SequenceEnd : ParsingEvent, ISequenceEnd
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class SequenceStart : NodeEvent, ISequenceStart public class SequenceStart : NodeEvent, ISequenceStart
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

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

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

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class StreamEnd : ParsingEvent, IStreamEnd public class StreamEnd : ParsingEvent, IStreamEnd
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
/// </summary> /// </summary>
public class StreamStart : ParsingEvent, IStreamStart public class StreamStart : ParsingEvent, IStreamStart
{ {
/// <summary> /// <summary>
/// Gets a value indicating the variation of depth caused by this event. /// 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, /// 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> /// </summary>
public override int NestingIncrease { public override int NestingIncrease {
get { get {

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

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

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

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

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

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

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

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

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

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

@ -39,7 +39,7 @@ namespace YamlDotNet.Core
/// <summary> /// <summary>
/// Gets the position in the input stream where the event that originated the exception ends. /// Gets the position in the input stream where the event that originated the exception ends.
/// </summary> /// </summary>
public Mark End { get; private set; } public Mark End { get; private set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="YamlException"/> class. /// 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
using System; using System;
namespace YamlDotNet.RepresentationModel namespace YamlDotNet.RepresentationModel
{ {
/// <summary> /// <summary>
/// Defines the method needed to be able to visit Yaml elements. /// Defines the method needed to be able to visit Yaml elements.
/// </summary> /// </summary>
public interface IYamlVisitor public interface IYamlVisitor
{ {
/// <summary> /// <summary>
/// Visits a <see cref="YamlStream"/>. /// Visits a <see cref="YamlStream"/>.
/// </summary> /// </summary>
/// <param name="stream"> /// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited. /// The <see cref="YamlStream"/> that is being visited.
/// </param> /// </param>
void Visit(YamlStream stream); void Visit(YamlStream stream);
/// <summary> /// <summary>
/// Visits a <see cref="YamlDocument"/>. /// Visits a <see cref="YamlDocument"/>.
/// </summary> /// </summary>
/// <param name="document"> /// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited. /// The <see cref="YamlDocument"/> that is being visited.
/// </param> /// </param>
void Visit(YamlDocument document); void Visit(YamlDocument document);
/// <summary> /// <summary>
/// Visits a <see cref="YamlScalarNode"/>. /// Visits a <see cref="YamlScalarNode"/>.
/// </summary> /// </summary>
/// <param name="scalar"> /// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited. /// The <see cref="YamlScalarNode"/> that is being visited.
/// </param> /// </param>
void Visit(YamlScalarNode scalar); void Visit(YamlScalarNode scalar);
/// <summary> /// <summary>
/// Visits a <see cref="YamlSequenceNode"/>. /// Visits a <see cref="YamlSequenceNode"/>.
/// </summary> /// </summary>
/// <param name="sequence"> /// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited. /// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param> /// </param>
void Visit(YamlSequenceNode sequence); void Visit(YamlSequenceNode sequence);
/// <summary> /// <summary>
/// Visits a <see cref="YamlMappingNode"/>. /// Visits a <see cref="YamlMappingNode"/>.
/// </summary> /// </summary>
/// <param name="mapping"> /// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited. /// The <see cref="YamlMappingNode"/> that is being visited.
/// </param> /// </param>
void Visit(YamlMappingNode mapping); void Visit(YamlMappingNode mapping);
} }
} }

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

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

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

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

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

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

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

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

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

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

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

@ -26,6 +26,31 @@ using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel.Serialization.NodeDeserializers 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, // 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using YamlDotNet.Core; using YamlDotNet.Core;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -9,7 +9,7 @@
// so, subject to the following conditions: // so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all // 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 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

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

@ -27,151 +27,235 @@ using Xunit;
using Xunit.Extensions; using Xunit.Extensions;
using YamlDotNet.Core; using YamlDotNet.Core;
using YamlDotNet.Core.Events; using YamlDotNet.Core.Events;
using YamlDotNet.RepresentationModel; using YamlDotNet.RepresentationModel;
namespace YamlDotNet.UnitTests namespace YamlDotNet.UnitTests
{ {
public class EmitterTests : YamlTest public class EmitterTests : YamlTest
{ {
private void ParseAndEmit(string name) { private void ParseAndEmit(string name) {
string testText = YamlFile(name).ReadToEnd(); string testText = YamlFile(name).ReadToEnd();
IParser parser = new Parser(new StringReader(testText)); IParser parser = new Parser(new StringReader(testText));
using(StringWriter output = new StringWriter()) { using(StringWriter output = new StringWriter()) {
IEmitter emitter = new Emitter(output, 2, int.MaxValue, false); IEmitter emitter = new Emitter(output, 2, int.MaxValue, false);
while(parser.MoveNext()) { while(parser.MoveNext()) {
//Console.WriteLine(parser.Current.GetType().Name); //Console.WriteLine(parser.Current.GetType().Name);
Console.Error.WriteLine(parser.Current); Console.Error.WriteLine(parser.Current);
emitter.Emit(parser.Current); emitter.Emit(parser.Current);
} }
string result = output.ToString(); string result = output.ToString();
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("------------------------------"); Console.WriteLine("------------------------------");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(testText); Console.WriteLine(testText);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("------------------------------"); Console.WriteLine("------------------------------");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(result); Console.WriteLine(result);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("------------------------------"); Console.WriteLine("------------------------------");
Console.WriteLine(); Console.WriteLine();
/* /*
Parser resultParser = new Parser(new StringReader(result)); Parser resultParser = new Parser(new StringReader(result));
while(resultParser.MoveNext()) { while(resultParser.MoveNext()) {
Console.WriteLine(resultParser.Current.GetType().Name); Console.WriteLine(resultParser.Current.GetType().Name);
} }
*/ */
/* /*
if(testText != result) { if(testText != result) {
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("------------------------------"); Console.WriteLine("------------------------------");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Expected:"); Console.WriteLine("Expected:");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(testText); Console.WriteLine(testText);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("------------------------------"); Console.WriteLine("------------------------------");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Result:"); Console.WriteLine("Result:");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(result); Console.WriteLine(result);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("------------------------------"); Console.WriteLine("------------------------------");
Console.WriteLine(); Console.WriteLine();
} }
Assert.Equal(testText, result); Assert.Equal(testText, result);
*/ */
} }
} }
[Fact] [Fact]
public void EmitExample1() public void EmitExample1()
{ {
ParseAndEmit("test1.yaml"); ParseAndEmit("test1.yaml");
} }
[Fact] [Fact]
public void EmitExample2() public void EmitExample2()
{ {
ParseAndEmit("test2.yaml"); ParseAndEmit("test2.yaml");
} }
[Fact] [Fact]
public void EmitExample3() public void EmitExample3()
{ {
ParseAndEmit("test3.yaml"); ParseAndEmit("test3.yaml");
} }
[Fact] [Fact]
public void EmitExample4() public void EmitExample4()
{ {
ParseAndEmit("test4.yaml"); ParseAndEmit("test4.yaml");
} }
[Fact] [Fact]
public void EmitExample5() public void EmitExample5()
{ {
ParseAndEmit("test5.yaml"); ParseAndEmit("test5.yaml");
} }
[Fact] [Fact]
public void EmitExample6() public void EmitExample6()
{ {
ParseAndEmit("test6.yaml"); ParseAndEmit("test6.yaml");
} }
[Fact] [Fact]
public void EmitExample7() public void EmitExample7()
{ {
ParseAndEmit("test7.yaml"); ParseAndEmit("test7.yaml");
} }
[Fact] [Fact]
public void EmitExample8() public void EmitExample8()
{ {
ParseAndEmit("test8.yaml"); ParseAndEmit("test8.yaml");
} }
[Fact] [Fact]
public void EmitExample9() public void EmitExample9()
{ {
ParseAndEmit("test9.yaml"); ParseAndEmit("test9.yaml");
} }
[Fact] [Fact]
public void EmitExample10() public void EmitExample10()
{ {
ParseAndEmit("test10.yaml"); ParseAndEmit("test10.yaml");
} }
[Fact] [Fact]
public void EmitExample11() public void EmitExample11()
{ {
ParseAndEmit("test11.yaml"); ParseAndEmit("test11.yaml");
} }
[Fact] [Fact]
public void EmitExample12() public void EmitExample12()
{ {
ParseAndEmit("test12.yaml"); ParseAndEmit("test12.yaml");
} }
[Fact] [Fact]
public void EmitExample13() public void EmitExample13()
{ {
ParseAndEmit("test13.yaml"); ParseAndEmit("test13.yaml");
} }
[Fact] [Fact]
public void EmitExample14() public void EmitExample14()
{ {
ParseAndEmit("test14.yaml"); 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) private string EmitScalar(Scalar scalar)
@ -270,5 +354,5 @@ namespace YamlDotNet.UnitTests
Assert.Equal(input, value.Value); 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
using System; using System;
using YamlDotNet.Core; using YamlDotNet.Core;
using Xunit; using Xunit;
namespace YamlDotNet.UnitTests namespace YamlDotNet.UnitTests
{ {
public class InsertionQueueTests public class InsertionQueueTests
{ {
[Fact] [Fact]
public void QueueWorks() { public void QueueWorks() {
InsertionQueue<int> queue = new InsertionQueue<int>(); InsertionQueue<int> queue = new InsertionQueue<int>();
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
queue.Enqueue(i); queue.Enqueue(i);
} }
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
for (int i = 0; i < 50; ++i) { for (int i = 0; i < 50; ++i) {
queue.Enqueue(i); queue.Enqueue(i);
} }
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
for (int i = 50; i < 100; ++i) { for (int i = 50; i < 100; ++i) {
queue.Enqueue(i); queue.Enqueue(i);
} }
for (int i = 10; i < 100; ++i) { for (int i = 10; i < 100; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
} }
[Fact] [Fact]
public void InsertWorks() { public void InsertWorks() {
InsertionQueue<int> queue = new InsertionQueue<int>(); InsertionQueue<int> queue = new InsertionQueue<int>();
for(int j = 0; j < 2; ++j) { for(int j = 0; j < 2; ++j) {
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
queue.Enqueue(i); queue.Enqueue(i);
} }
queue.Insert(5, 99); queue.Insert(5, 99);
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
Assert.Equal(99, queue.Dequeue()); Assert.Equal(99, queue.Dequeue());
for (int i = 5; i < 10; ++i) { for (int i = 5; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
} }
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
queue.Enqueue(i); queue.Enqueue(i);
queue.Dequeue(); queue.Dequeue();
} }
for (int i = 0; i < 20; ++i) { for (int i = 0; i < 20; ++i) {
queue.Enqueue(i); queue.Enqueue(i);
} }
queue.Insert(5, 99); queue.Insert(5, 99);
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
Assert.Equal(99, queue.Dequeue()); Assert.Equal(99, queue.Dequeue());
for (int i = 5; i < 20; ++i) { for (int i = 5; i < 20; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
} }
[Fact] [Fact]
public void Dequeue_ThrowsExceptionWhenEmpty() { public void Dequeue_ThrowsExceptionWhenEmpty() {
InsertionQueue<int> queue = new InsertionQueue<int>(); InsertionQueue<int> queue = new InsertionQueue<int>();
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
queue.Enqueue(i); queue.Enqueue(i);
} }
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
Assert.Equal(i, queue.Dequeue()); Assert.Equal(i, queue.Dequeue());
} }
Assert.Throws<InvalidOperationException>(() => 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using Xunit; using Xunit;
using YamlDotNet.Core; using YamlDotNet.Core;
using YamlDotNet.Core.Events; using YamlDotNet.Core.Events;
namespace YamlDotNet.UnitTests namespace YamlDotNet.UnitTests
{ {
public class LookAheadBufferTests public class LookAheadBufferTests
{ {
private static LookAheadBuffer CreateBuffer(string text, int capacity) { private static LookAheadBuffer CreateBuffer(string text, int capacity) {
return new LookAheadBuffer(new StringReader(text), capacity); return new LookAheadBuffer(new StringReader(text), capacity);
} }
[Fact] [Fact]
public void ReadingWorks() public void ReadingWorks()
{ {
LookAheadBuffer buffer = CreateBuffer("abcdefghi", 4); LookAheadBuffer buffer = CreateBuffer("abcdefghi", 4);
FieldInfo count = buffer.GetType().GetField("count", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo count = buffer.GetType().GetField("count", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.NotNull(count); Assert.NotNull(count);
Assert.Equal(0, count.GetValue(buffer)); Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('a', buffer.Peek(0)); Assert.Equal('a', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer)); Assert.Equal(1, count.GetValue(buffer));
Assert.Equal('b', buffer.Peek(1)); Assert.Equal('b', buffer.Peek(1));
Assert.Equal(2, count.GetValue(buffer)); Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('c', buffer.Peek(2)); Assert.Equal('c', buffer.Peek(2));
Assert.Equal(3, count.GetValue(buffer)); Assert.Equal(3, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(2, count.GetValue(buffer)); Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('b', buffer.Peek(0)); Assert.Equal('b', buffer.Peek(0));
Assert.Equal(2, count.GetValue(buffer)); Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('c', buffer.Peek(1)); Assert.Equal('c', buffer.Peek(1));
Assert.Equal(2, count.GetValue(buffer)); Assert.Equal(2, count.GetValue(buffer));
Assert.Equal('d', buffer.Peek(2)); Assert.Equal('d', buffer.Peek(2));
Assert.Equal(3, count.GetValue(buffer)); Assert.Equal(3, count.GetValue(buffer));
Assert.Equal('e', buffer.Peek(3)); Assert.Equal('e', buffer.Peek(3));
Assert.Equal(4, count.GetValue(buffer)); Assert.Equal(4, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(3, count.GetValue(buffer)); Assert.Equal(3, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(2, count.GetValue(buffer)); Assert.Equal(2, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(1, count.GetValue(buffer)); Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer)); Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('f', buffer.Peek(0)); Assert.Equal('f', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer)); Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer)); Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('g', buffer.Peek(0)); Assert.Equal('g', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer)); Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer)); Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('h', buffer.Peek(0)); Assert.Equal('h', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer)); Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer)); Assert.Equal(0, count.GetValue(buffer));
Assert.Equal('i', buffer.Peek(0)); Assert.Equal('i', buffer.Peek(0));
Assert.Equal(1, count.GetValue(buffer)); Assert.Equal(1, count.GetValue(buffer));
buffer.Skip(1); buffer.Skip(1);
Assert.Equal(0, count.GetValue(buffer)); Assert.Equal(0, count.GetValue(buffer));
Assert.False(buffer.EndOfInput); Assert.False(buffer.EndOfInput);
Assert.Equal('\0', buffer.Peek(0)); Assert.Equal('\0', buffer.Peek(0));
Assert.True(buffer.EndOfInput); Assert.True(buffer.EndOfInput);
Assert.Equal(0, count.GetValue(buffer)); Assert.Equal(0, count.GetValue(buffer));
} }
} }
} }

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

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

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

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

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