fix: Fixed a bug where AbstractGenericXmlConverter was not reading out of empty elements

This commit is contained in:
Chris Cameron
2021-05-04 17:26:01 -04:00
parent ae10abd71e
commit b3c1daaab5
2 changed files with 170 additions and 30 deletions

View File

@@ -111,39 +111,24 @@ namespace ICD.Common.Utils.Xml
if (reader.NodeType != XmlNodeType.Element && !reader.ReadToNextElement())
throw new FormatException();
T output = default(T);
bool instantiated = false;
bool isEmpty = reader.IsEmptyElement;
T output = Instantiate();
// Read the root attributes
while (reader.MoveToNextAttribute())
ReadAttribute(reader, output);
// Read out of the root element
if (!reader.Read())
throw new FormatException();
// There were no child elements
if (isEmpty)
return output;
// Read through child elements
while (true)
{
if (!instantiated)
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.IsEmptyElement)
return default(T);
output = Instantiate();
instantiated = true;
// Read the root attributes
while (reader.MoveToNextAttribute())
ReadAttribute(reader, output);
// Read out of the root element
if (!reader.Read())
throw new FormatException();
continue;
default:
// Keep reading until we reach the root element.
if (!reader.Read())
throw new FormatException();
continue;
}
}
switch (reader.NodeType)
{
case XmlNodeType.Element: