Skip to content

Commit

Permalink
add XmlExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Jun 25, 2022
1 parent 7a268b9 commit 2e17245
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Signum.Utilities/Extensions/XmlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace Signum.Utilities;
Expand Down Expand Up @@ -45,4 +46,22 @@ public static T DeserializeFromXml<T>(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;
}
}

0 comments on commit 2e17245

Please sign in to comment.