XHelper
This static class holds various methods that are useful in saving and loading model data to and from Linq for XML XElements.
Methods
public static XAttribute Attribute(XName n, IEnumerable<double> v, IEnumerable<double> defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a sequence of Double values, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, double v, double defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Double value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, Guid v, Guid defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Guid value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, IEnumerable<int> v, IEnumerable<int> defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a sequence of Int32 values, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, decimal v, decimal defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Decimal value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, Point v, Point defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Point value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, int v, int defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for an Int32 value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, Thickness v, Thickness defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Thickness value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, Size v, Size defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Size value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, bool v, bool defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Boolean value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, IEnumerable<Point> v, IEnumerable<Point> defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a sequence of Point values, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, DateTime v, DateTime defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a DateTime value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, string v, string defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a String value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, Rect v, Rect defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a Rect value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute(XName n, TimeSpan v, TimeSpan defval)
result = XHelper.Attribute(n, v, defval)
Generate an XAttribute for a TimeSpan value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute AttributeEnum<T>(XName n, T v, T defval)
result = XHelper.AttributeEnum(n, v, defval)
Generate an XAttribute for an enumerated type value, unless the value is equal to the given default value.
- n
- the attribute name, often the same as the data's property name
- v
- the property value
- defval
- the default value for the property
Returns: an XAttribute or null
public static XAttribute Attribute<T>(XName n, T v, T defval, Func<T, string> conv)
result = XHelper.Attribute(n, v, defval, conv)
This generic method produces an XAttribute with the given value if the value is not equal to the given default value, using the given conversion function to convert the value to a string.
- n
- the name of the XAttribute
- v
- the value
- defval
- the default value for this attribute/property
- conv
- a function from to String
Returns: an XAttribute, or null if the value is null or if it is equal to the default value
public static XElement Elements<T>(XName n, XName c, IEnumerable v, Func<T, string> conv)
result = XHelper.Elements(n, c, v, conv)
Generate an XElement containing nested child XElements, one for each item in the given collection.
- n
- the name for the new XElement
- c
- the name for the child elements
- v
- conv
Returns: an XElement or null if the given collection was null or empty
public static double Read(XName n, XElement e, double defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Double, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static IEnumerable<int> Read(XName n, XElement e, IEnumerable<int> defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Thickness, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static TimeSpan Read(XName n, XElement e, TimeSpan defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a TimeSpan, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static int Read(XName n, XElement e, int defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to an Int32, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static Point Read(XName n, XElement e, Point defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Point, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static IEnumerable<double> Read(XName n, XElement e, IEnumerable<double> defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Thickness, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static DateTime Read(XName n, XElement e, DateTime defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a DateTime, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static bool Read(XName n, XElement e, bool defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Boolean, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static Size Read(XName n, XElement e, Size defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Size, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static string Read(XName n, XElement e, string defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a String, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static Thickness Read(XName n, XElement e, Thickness defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Thickness, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static IEnumerable<Point> Read(XName n, XElement e, IEnumerable<Point> defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Thickness, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static Rect Read(XName n, XElement e, Rect defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Rect, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static Guid Read(XName n, XElement e, Guid defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Guid, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static decimal Read(XName n, XElement e, decimal defval)
result = XHelper.Read(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to a Decimal, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the expected data type, or the default value
public static IEnumerable ReadElements<T>(XContainer e, XName c, ICollection<T> coll, Func<string, T> conv)
result = XHelper.ReadElements(e, c, coll, conv)
Consume an XContainer that is assumed to hold a collection of nested child XElements each holding a value to be converted to the given data type.
- e
- the XContainer to be read
- c
- the name of the child elements
- coll
- an empty collection to which items are added
- conv
- a conversion function from String to the item data type,
Returns: the collection, containing all of the data items that were read
public static T ReadEnum<T>(XName n, XElement e, T defval)
result = XHelper.ReadEnum(n, e, defval)
Consume an XAttribute on an XElement, converting the attribute's value to an enumerated type, or return the default value if the attribute is not present or if there is a conversion exception.
- n
- the attribute name, often the same as the data's property name
- e
- the XElement holding the expected attribute
- defval
- the default value for the property
Returns: the attribute value converted to the , or the default value
public static T Read<T>(XName n, XElement e, T defval, Func<string, T> conv)
result = XHelper.Read(n, e, defval, conv)
This generic method produces a property value from an XElement's attribute value, using a conversion function to convert the string to the expected type, and returning a default value if the conversion fails.
- n
- the name of the attribute
- e
- the XElement that may have an XAttribute with the name
- defval
- the default value to return if there's no attribute named or if the attribute value string cannot be converted to the value type
- conv
- a function from String to
Returns: either the attribute value string converted to , or else the
public static bool ToBoolean(string s)
result = XHelper.ToBoolean(s)
This data conversion function converts a String to a Boolean.
- s
public static DateTime ToDateTime(string s)
result = XHelper.ToDateTime(s)
This data conversion function converts a String to a DateTime.
- s
public static decimal ToDecimal(string s)
result = XHelper.ToDecimal(s)
This data conversion function converts a String to a Decimal.
- s
public static double ToDouble(string s)
result = XHelper.ToDouble(s)
This data conversion function converts a String to a Double.
- s
public static Guid ToGuid(string s)
result = XHelper.ToGuid(s)
This data conversion function converts a String to a Guid.
- s
public static IEnumerable<double> ToIEnumerableOfDouble(string s)
result = XHelper.ToIEnumerableOfDouble(s)
This data conversion function converts a String to a sequence of Doubles.
- s
public static IEnumerable<int> ToIEnumerableOfInt32(string s)
result = XHelper.ToIEnumerableOfInt32(s)
This data conversion function converts a String to a sequence of Int32.
- s
public static IEnumerable<Point> ToIEnumerableOfPoint(string s)
result = XHelper.ToIEnumerableOfPoint(s)
This data conversion function converts a String to a sequence of Points.
- s
public static int ToInt32(string s)
result = XHelper.ToInt32(s)
This data conversion function converts a String to an Int32.
- s
public static Point ToPoint(string s)
result = XHelper.ToPoint(s)
This data conversion function converts a String to a Point.
- s
public static Rect ToRect(string s)
result = XHelper.ToRect(s)
This data conversion function converts a String to a Rect.
- s
public static Size ToSize(string s)
result = XHelper.ToSize(s)
This data conversion function converts a String to a Size.
- s
public static string ToString(double v)
result = XHelper.ToString(v)
This data conversion function converts a Double to a String.
- v
public static string ToString(Thickness v)
result = XHelper.ToString(v)
This data conversion function converts a Thickness to a String.
- v
public static string ToString(IEnumerable<Point> v)
result = XHelper.ToString(v)
This data conversion function converts a sequence of Point values to a String.
- v
public static string ToString(string v)
result = XHelper.ToString(v)
This data conversion function converts a String to a String by just returning its argument.
- v
public static string ToString(Size v)
result = XHelper.ToString(v)
This data conversion function converts a Size to a String.
- v
public static string ToString(IEnumerable<double> v)
result = XHelper.ToString(v)
This data conversion function converts a sequence of Double values to a String.
- v
public static string ToString(decimal v)
result = XHelper.ToString(v)
This data conversion function converts a Decimal to a String.
- v
public static string ToString(bool v)
result = XHelper.ToString(v)
This data conversion function converts a Boolean to a String.
- v
public static string ToString(Point v)
result = XHelper.ToString(v)
This data conversion function converts a Point to a String.
- v
public static string ToString(IEnumerable<int> v)
result = XHelper.ToString(v)
This data conversion function converts a sequence of Int32 values to a String.
- v
public static string ToString(int v)
result = XHelper.ToString(v)
This data conversion function converts an Int32 to a String.
- v
public static string ToString(TimeSpan v)
result = XHelper.ToString(v)
This data conversion function converts a TimeSpan to a String.
- v
public static string ToString(Rect v)
result = XHelper.ToString(v)
This data conversion function converts a Rect to a String.
- v
public static string ToString(DateTime v)
result = XHelper.ToString(v)
This data conversion function converts a DateTime to a String.
- v
public static string ToString(Guid v)
result = XHelper.ToString(v)
This data conversion function converts a Guid to a String.
- v
public static Thickness ToThickness(string s)
result = XHelper.ToThickness(s)
This data conversion function converts a String to a Thickness.
- s
public static TimeSpan ToTimeSpan(string s)
result = XHelper.ToTimeSpan(s)
This data conversion function converts a String to a TimeSpan.
- s