Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Globalization;
- using System.Xml.Linq;
- namespace Demo.Utility
- {
- public static class XmlUtilites
- {
- public static string ElementValue(this XElement element, string childName, string defaultValue = null)
- {
- if (element == null) return defaultValue;
- var child = element.Element(childName);
- return child != null ? child.Value : defaultValue;
- }
- public static double ElementDoubleValue(this XElement element, string childName, CultureInfo cultureInfo = null)
- {
- if (element == null) return defaultValue;
- var culture = cultureInfo ?? CultureInfo.InvariantCulture;
- var child = element.Element(childName);
- return child != null && !string.IsNullOrEmpty(child.Value) ? double.Parse(child.Value, culture) : double.NaN;
- }
- public static decimal ElementDecimalValue(this XElement element, string childName, CultureInfo cultureInfo = null)
- {
- if (element == null) return defaultValue;
- var child = element.Element(childName);
- var culture = cultureInfo ?? CultureInfo.InvariantCulture;
- return child != null && !string.IsNullOrEmpty(child.Value)
- ? decimal.Parse(child.Value, culture)
- : 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement