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 удалений

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

@ -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;
}
}
} }

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

@ -174,6 +174,90 @@ namespace YamlDotNet.UnitTests
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)
{ {
return Emit( return Emit(

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

@ -614,14 +614,14 @@ namespace YamlDotNet.UnitTests.RepresentationModel
{ {
public bool Accepts(Type type) { return type == typeof(SomeCustomeType); } public bool Accepts(Type type) { return type == typeof(SomeCustomeType); }
public object ReadYaml(IParser parser, Type type) public object ReadYaml(Parser parser, Type type)
{ {
var value = ((Scalar)parser.Current).Value; var value = ((Scalar)parser.Current).Value;
parser.MoveNext(); parser.MoveNext();
return new SomeCustomeType(value); return new SomeCustomeType(value);
} }
public void WriteYaml(IEmitter emitter, object value, Type type) public void WriteYaml(Emitter emitter, object value, Type type)
{ {
emitter.Emit(new Scalar(((SomeCustomeType)value).Value)); emitter.Emit(new Scalar(((SomeCustomeType)value).Value));
} }