зеркало из https://github.com/stride3d/SharpYaml.git
Merge pull request #32 from roji/deserialize_empty
Fixed empty document deserialization
This commit is contained in:
Коммит
5573322ea6
|
@ -167,7 +167,9 @@ namespace YamlDotNet.RepresentationModel.Serialization
|
|||
|
||||
var hasDocumentStart = reader.Allow<DocumentStart>() != null;
|
||||
|
||||
var result = valueDeserializer.DeserializeValue(reader, type, new SerializerState(), valueDeserializer);
|
||||
object result = null;
|
||||
if (!reader.Accept<DocumentEnd>() && !reader.Accept<StreamEnd>())
|
||||
result = valueDeserializer.DeserializeValue(reader, type, new SerializerState(), valueDeserializer);
|
||||
|
||||
if (hasDocumentStart)
|
||||
{
|
||||
|
|
|
@ -296,7 +296,9 @@ namespace YamlDotNet.RepresentationModel.Serialization
|
|||
reader.Expect<DocumentStart>();
|
||||
}
|
||||
|
||||
object result = DeserializeValue(reader, serializedType, internalContext);
|
||||
object result = null;
|
||||
if (!reader.Accept<DocumentEnd>() && !reader.Accept<StreamEnd>())
|
||||
result = DeserializeValue(reader, serializedType, internalContext);
|
||||
|
||||
if (hasDocumentStart)
|
||||
{
|
||||
|
|
|
@ -1094,6 +1094,23 @@ Name: Charles
|
|||
Assert.Equal("Brad", people[1].Name);
|
||||
Assert.Equal("Charles", people[2].Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeserializeEmptyDocument()
|
||||
{
|
||||
var deserializer = new Deserializer();
|
||||
var arr = (int[])deserializer.Deserialize(new StringReader(""), typeof(int[]));
|
||||
Assert.Null(arr);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Obsolete]
|
||||
public void DeserializeEmptyDocumentYamlDeserializer()
|
||||
{
|
||||
var deserializer = new YamlSerializer<int[]>();
|
||||
var arr = deserializer.Deserialize(new StringReader(""));
|
||||
Assert.Null(arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче