Rethrowing XmlExceptions as IcdXmlExceptions

This commit is contained in:
Chris Cameron
2017-07-21 11:01:32 -04:00
parent 442bd20759
commit 323300f710
4 changed files with 115 additions and 15 deletions

View File

@@ -28,7 +28,7 @@ namespace ICD.Common.Utils.Xml
}
catch (XmlException e)
{
throw new IcdXmlException(e.Message, e, e.LineNumber, e.LinePosition);
throw new IcdXmlException(e);
}
}

View File

@@ -1,4 +1,9 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp;
#else
using System.Xml;
#endif
namespace ICD.Common.Utils.Xml
{
@@ -20,5 +25,14 @@ namespace ICD.Common.Utils.Xml
m_LineNumber = lineNumber;
m_LinePosition = linePosition;
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="inner"></param>
public IcdXmlException(XmlException inner)
: this(inner.Message, inner, inner.LineNumber, inner.LinePosition)
{
}
}
}

View File

@@ -50,26 +50,54 @@ namespace ICD.Common.Utils.Xml
public bool MoveToNextAttribute()
{
return m_Reader.MoveToNextAttribute();
try
{
return m_Reader.MoveToNextAttribute();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public void MoveToElement()
{
m_Reader.MoveToElement();
try
{
m_Reader.MoveToElement();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public string GetAttribute(string name)
{
return m_Reader.GetAttribute(name);
try
{
return m_Reader.GetAttribute(name);
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public string ReadString()
{
try
{
#if SIMPLSHARP
return m_Reader.ReadString();
return m_Reader.ReadString();
#else
return m_Reader.ReadElementContentAsString();
return m_Reader.ReadElementContentAsString();
#endif
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public bool Read()
@@ -80,47 +108,96 @@ namespace ICD.Common.Utils.Xml
}
catch (XmlException e)
{
throw new IcdXmlException(e.Message, e, e.LineNumber, e.LinePosition);
throw new IcdXmlException(e);
}
}
public void Dispose()
{
try
{
#if SIMPLSHARP
m_Reader.Dispose(true);
m_Reader.Dispose(true);
#else
m_Reader.Dispose();
m_Reader.Dispose();
#endif
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public void Skip()
{
m_Reader.Skip();
try
{
m_Reader.Skip();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public string ReadElementContentAsString()
{
return m_Reader.ReadElementContentAsString();
try
{
return m_Reader.ReadElementContentAsString();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public string ReadOuterXml()
{
return m_Reader.ReadOuterXml();
try
{
return m_Reader.ReadOuterXml();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public string ReadInnerXml()
{
return m_Reader.ReadInnerXml();
try
{
return m_Reader.ReadInnerXml();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public long ReadElementContentAsLong()
{
return m_Reader.ReadElementContentAsLong();
try
{
return m_Reader.ReadElementContentAsLong();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
public float ReadElementContentAsFloat()
{
return m_Reader.ReadElementContentAsFloat();
try
{
return m_Reader.ReadElementContentAsFloat();
}
catch (XmlException e)
{
throw new IcdXmlException(e);
}
}
#endregion

View File

@@ -135,6 +135,9 @@ namespace ICD.Common.Utils.Xml
[PublicAPI]
public static void Recurse(string xml, Action<XmlRecursionEventArgs> callback)
{
if (callback == null)
throw new ArgumentNullException("callback");
Recurse(xml, new Stack<string>(), callback);
}
@@ -146,6 +149,12 @@ namespace ICD.Common.Utils.Xml
/// <param name="callback"></param>
private static void Recurse(string xml, Stack<string> path, Action<XmlRecursionEventArgs> callback)
{
if (path == null)
throw new ArgumentNullException("path");
if (callback == null)
throw new ArgumentNullException("callback");
IcdXmlReader childReader;
try