public static LocatedNullable <bool> GetOptionalBool( this XElement elem, string name, bool?defaultValue = null) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { return(Located.Create(defaultValue)); } if (attrib.Value == "true" || attrib.Value == "1") { return(Located.Create((bool?)true, attrib.GetValueLocation())); } if (attrib.Value == "false" || attrib.Value == "0") { return(Located.Create((bool?)false, attrib.GetValueLocation())); } throw CreateInvalidBoolValueException(attrib); }
public static LocatedRef <string> GetString(this XElement elem, string name) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { throw CreateMissingAttributeException(elem, name); } return(Located.Create(attrib.Value, attrib.GetValueLocation())); }
public static LocatedRef <string> GetCSymbol( this XElement elem, string name, string defaultValue = null) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { return(Located.Create(defaultValue)); } return(Located.Create(attrib.Value, attrib.GetValueLocation())); }
public static LocatedVal <Guid> GetGuid(this XElement elem, string name) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { throw CreateMissingAttributeException(elem, name); } if (!Guid.TryParseExact(attrib.Value, "B", out var value)) { throw CreateInvalidNumberValueException <byte>(attrib); } return(Located.Create(value, attrib.GetValueLocation())); }
public static LocatedVal <ulong> GetHexInt64(this XElement elem, string name) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { throw CreateMissingAttributeException(elem, name); } if (!TryParse(attrib.Value, NumberFormat.PrefixedHex, out ulong value)) { throw CreateInvalidHexNumberValueException <ulong>(attrib); } return(Located.Create(value, attrib.GetValueLocation())); }
public static LocatedVal <uint> GetUInt32(this XElement elem, string name) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { throw CreateMissingAttributeException(elem, name); } if (!TryParse(attrib.Value, NumberFormat.HexDec, out uint value)) { throw CreateInvalidNumberValueException <uint>(attrib); } return(Located.Create(value, attrib.GetValueLocation())); }
public static LocatedRef <QName> GetQName(this XElement elem, string name) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { throw CreateMissingAttributeException(elem, name); } return(Located.Create( QName.Parse(attrib.Value, new XElementNamespaceResolver(elem)), attrib.GetValueLocation())); }
public static LocatedNullable <Guid> GetOptionalGuid( this XElement elem, string name, Guid?defaultValue = null) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { return(Located.Create(defaultValue)); } if (!Guid.TryParseExact(attrib.Value, "B", out var value)) { throw CreateInvalidNumberValueException <byte>(attrib); } return(Located.Create((Guid?)value, attrib.GetValueLocation())); }
public static LocatedNullable <ushort> GetOptionalUInt16( this XElement elem, string name, ushort?defaultValue = null) { if (elem == null) { throw new ArgumentNullException(nameof(elem)); } XAttribute attrib = elem.Attribute(name); if (attrib == null) { return(Located.Create(defaultValue)); } if (!TryParse(attrib.Value, NumberFormat.HexDec, out ushort value)) { throw CreateInvalidNumberValueException <ushort>(attrib); } return(Located.Create((ushort?)value, attrib.GetValueLocation())); }