From 2e1724558d9105de98df0dd3c6bef8f27a3f7166 Mon Sep 17 00:00:00 2001 From: Olmo del Corral Cano Date: Sun, 26 Jun 2022 01:40:36 +0200 Subject: [PATCH] add XmlExtensions --- Signum.Utilities/Extensions/XmlExtensions.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Signum.Utilities/Extensions/XmlExtensions.cs b/Signum.Utilities/Extensions/XmlExtensions.cs index a38caf5f9d..c795ff0489 100644 --- a/Signum.Utilities/Extensions/XmlExtensions.cs +++ b/Signum.Utilities/Extensions/XmlExtensions.cs @@ -1,5 +1,6 @@ using System.IO; using System.Xml; +using System.Xml.Linq; using System.Xml.Serialization; namespace Signum.Utilities; @@ -45,4 +46,22 @@ public static T DeserializeFromXml(string str) return (T)serializer.Deserialize(reader)!; } } + + public static XAttribute AttributeEx(this XElement element, XName name) + { + var att = element.Attribute(name); + if (att == null) + throw new InvalidOperationException($"Attribute '{name}' not found"); + + return att; + } + + public static XElement ElementEx(this XElement element, XName name) + { + var elem = element.Element(name); + if (elem == null) + throw new InvalidOperationException($"Element '{name}' not found"); + + return elem; + } }