From 79621dcfda019c3b1dfa2ca5885b18d8710ed1bf Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 20 Jul 2017 13:05:34 -0400 Subject: [PATCH] Better exception when an attribute does not exist --- ICD.Common.Utils/Xml/XmlUtils.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ICD.Common.Utils/Xml/XmlUtils.cs b/ICD.Common.Utils/Xml/XmlUtils.cs index 5196045..bba7bdc 100644 --- a/ICD.Common.Utils/Xml/XmlUtils.cs +++ b/ICD.Common.Utils/Xml/XmlUtils.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using ICD.Common.EventArguments; using ICD.Common.Properties; +using ICD.Common.Utils.Extensions; using ICD.Common.Utils.IO; namespace ICD.Common.Utils.Xml @@ -67,7 +68,11 @@ namespace ICD.Common.Utils.Xml [PublicAPI] 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)); } ///