mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 20:54:58 +00:00
perf: Avoid throwing exceptions in XmlReaderExtensions
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.EventArguments;
|
using ICD.Common.Utils.EventArguments;
|
||||||
|
using ICD.Common.Utils.Extensions;
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
using Crestron.SimplSharp.CrestronXml;
|
using Crestron.SimplSharp.CrestronXml;
|
||||||
#else
|
#else
|
||||||
@@ -193,14 +194,11 @@ namespace ICD.Common.Utils.Xml
|
|||||||
if (extends == null)
|
if (extends == null)
|
||||||
throw new ArgumentNullException("extends");
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
try
|
IcdXmlReader output;
|
||||||
{
|
if (extends.GetChildElements(element).TryFirst(out output))
|
||||||
return extends.GetChildElements(element).First();
|
return output;
|
||||||
}
|
|
||||||
catch (InvalidOperationException e)
|
throw new FormatException("No child element with name " + element);
|
||||||
{
|
|
||||||
throw new FormatException("No child element with name " + element, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -304,20 +302,12 @@ namespace ICD.Common.Utils.Xml
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static bool TryGetChildElementAsString(this IcdXmlReader extends, string element, out string output)
|
public static bool TryGetChildElementAsString(this IcdXmlReader extends, string element, out string output)
|
||||||
{
|
{
|
||||||
output = null;
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
try
|
return extends.GetChildElementsAsString(element).TryFirst(out output);
|
||||||
{
|
|
||||||
output = extends.GetChildElementsAsString(element).First();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (InvalidOperationException)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user