Northwoods.GoWPF 2.2.4 Assembly
XHelper Class
Members 

This static class holds various methods that are useful in saving and loading model data to and from Linq for XML XElements.
Syntax
Public MustInherit NotInheritable Class XHelper 
public static class XHelper 
Remarks

There are three kinds of methods defined in this class. There are basic data conversion methods, converting data types to and from Strings. There are methods that produce XAttributes and XElements containing given some data. There are methods that get data from XAttributes and XElements.

The conversion method names are all prefixed with "To". They use the XmlConvert methods for achieving their results. For the basic data types (String, bool, int, Guid, and double), the conversion methods are the same as the equivalent XmlConvert methods. For the additional data types (Point, Size, Rect, Thickness) the conversion methods assume the numbers are separated by spaces.

When generating XML using Linq for XML you will often want to avoid generating attributes or elements when the values are the same as the property defaults. To help with that situation the methods named "Attribute" take the attribute name, a property value, and the property's default value. If the value is null or if the value is equal to the default value, the method returns null; otherwise it returns a new XAttribute. This is convenient when building an XElement.

When consuming XML using Linq for XML you need to deal with situations where the expected attribute or child element is not present or where the value is in the wrong format or for some other reason cannot be converted to the expected data type. To help with these cases the methods named "Read" take the attribute name, the XElement on which the attribute may exist, and the default value for that property. If the XElement is null, or if it has no XAttribute with the given name, or if there is an exception converting the string value to the expected data type, it will return the default value.

There are also generic methods for handling enumerations and for sequences of data. For data sequences, of type IEnumerable, the methods will generate and expect to consume child elements, one for each item. You will need to specify the name of those child elements, and the conversion function for the item data type.

For examples of how to use these methods, look at the descriptions of the predefined data methods for making elements and loading data from them: MakeXElement, GraphLinksModelLinkData<NodeKey,PortKey>.MakeXElement, MakeXElement, MakeXElement, LoadFromXElement, GraphLinksModelLinkData<NodeKey,PortKey>.LoadFromXElement, LoadFromXElement, LoadFromXElement

Inheritance Hierarchy

System.Object
   Northwoods.GoXam.Model.XHelper

Requirements
See Also

Reference

XHelper Members
Northwoods.GoXam.Model Namespace

 

 


© Northwoods Software 2017. All Rights Reserved.

Send Feedback