mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
Better exception when an attribute does not exist
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using ICD.Common.EventArguments;
|
using ICD.Common.EventArguments;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.Extensions;
|
||||||
using ICD.Common.Utils.IO;
|
using ICD.Common.Utils.IO;
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Xml
|
namespace ICD.Common.Utils.Xml
|
||||||
@@ -67,7 +68,11 @@ namespace ICD.Common.Utils.Xml
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static IcdXmlAttribute GetAttribute(string xml, string name)
|
public static IcdXmlAttribute GetAttribute(string xml, string name)
|
||||||
{
|
{
|
||||||
return GetAttributes(xml).First(a => a.Name == name);
|
IcdXmlAttribute output;
|
||||||
|
if (GetAttributes(xml).TryFirstOrDefault(a => a.Name == name, out output))
|
||||||
|
return output;
|
||||||
|
|
||||||
|
throw new KeyNotFoundException(string.Format("No attribute with name {0}", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user