using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Xml;
using System.Xml.Linq;
public static class XmlUtility
{
public static int? GetValueAsInt32(this XAttribute attribute)
{
int i;
return (attribute != null) &&
int.TryParse(attribute.Value, out i) ?
i : (int?)null;
}
public static int? GetValueAsInt32(
this XAttribute attribute,
IFormatProvider formatProvider)
{
Debug.Assert(formatProvider != null, "formatProvider is null.");
int i;
return (attribute != null) &&
int.TryParse(attribute.Value,
NumberStyles.Integer,
formatProvider,
out i) ?
i : (int?)null;
}
public static int? GetValueAsInt32(this XElement element)
{
int i;
return (element != null) &&
int.TryParse(element.Value, out i) ?
i : (int?)null;
}
public static int? GetValueAsInt32(
this XElement element,
IFormatProvider formatProvider)
{
Debug.Assert(formatProvider != null, "formatProvider is null.");
int i;
return (element != null) &&
int.TryParse(
element.Value,
NumberStyles.Integer,
formatProvider,
out i) ?
i : (int?)null;
}
}