mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
fix: Xml converter over-reading fixes
This commit is contained in:
@@ -102,13 +102,13 @@ namespace ICD.Common.Utils.Xml
|
|||||||
public virtual T ReadXmlTyped(IcdXmlReader reader)
|
public virtual T ReadXmlTyped(IcdXmlReader reader)
|
||||||
{
|
{
|
||||||
// Read into the first node
|
// Read into the first node
|
||||||
if (!reader.Read())
|
if (reader.NodeType != XmlNodeType.Element && !reader.ReadToNextElement())
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
|
|
||||||
T output = default(T);
|
T output = default(T);
|
||||||
bool instantiated = false;
|
bool instantiated = false;
|
||||||
|
|
||||||
while (reader.NodeType != XmlNodeType.EndElement)
|
while (true)
|
||||||
{
|
{
|
||||||
if (!instantiated)
|
if (!instantiated)
|
||||||
{
|
{
|
||||||
@@ -121,6 +121,10 @@ namespace ICD.Common.Utils.Xml
|
|||||||
output = Instantiate();
|
output = Instantiate();
|
||||||
instantiated = true;
|
instantiated = true;
|
||||||
|
|
||||||
|
// Read the root attributes
|
||||||
|
while (reader.MoveToNextAttribute())
|
||||||
|
ReadAttribute(reader, output);
|
||||||
|
|
||||||
// Read out of the root element
|
// Read out of the root element
|
||||||
if (!reader.Read())
|
if (!reader.Read())
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
@@ -136,15 +140,13 @@ namespace ICD.Common.Utils.Xml
|
|||||||
|
|
||||||
switch (reader.NodeType)
|
switch (reader.NodeType)
|
||||||
{
|
{
|
||||||
case XmlNodeType.Attribute:
|
|
||||||
ReadAttribute(reader, output);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case XmlNodeType.Element:
|
case XmlNodeType.Element:
|
||||||
ReadElement(reader, output);
|
ReadElement(reader, output);
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
case XmlNodeType.EndElement:
|
case XmlNodeType.EndElement:
|
||||||
|
// Read out of the end element
|
||||||
|
reader.Read();
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -153,8 +155,6 @@ namespace ICD.Common.Utils.Xml
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -164,8 +164,6 @@ namespace ICD.Common.Utils.Xml
|
|||||||
/// <param name="instance"></param>
|
/// <param name="instance"></param>
|
||||||
protected virtual void ReadAttribute(IcdXmlReader reader, T instance)
|
protected virtual void ReadAttribute(IcdXmlReader reader, T instance)
|
||||||
{
|
{
|
||||||
// Skip the attribute
|
|
||||||
reader.Read();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user