LayoutSerializer Class |
Namespace: DigitalRune.Game.UI
The LayoutSerializer type exposes the following members.
Name | Description | |
---|---|---|
LayoutSerializer | Initializes a new instance of the LayoutSerializer class |
Name | Description | |
---|---|---|
Equals | (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Load(XContainer) |
Loads the objects specified in the given XML container.
| |
Load(XmlReader) |
Loads the objects specified in the given XML container.
| |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnCreateInstance(Type, XElement) |
Called when a game instance needs to be created.
| |
OnCreateInstance(Type, XmlReader) |
Called when a game instance needs to be created.
| |
OnGetType(XElement) |
Called to find a type for the given XML element.
| |
OnGetType(XmlReader) |
Called to find a type for the given XML element.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
Assemblies |
Gets assemblies that contain the types.
| |
DefaultNamespace |
Gets or sets the default namespace specified in the "Layout" node of the XML file.
|
The Load method reads an XML document, creates and returns the objects specified in the XML document. Here is an example XML file:
<?xml version="1.0" encoding="utf-8" ?> <Layout DefaultNamespace="DigitalRune.Game.UI.Controls"> <MyClass Namespace="NamespaceFoo1.Foo2"> <Data>123</Data> </MyClass> <Button Name="Button0"> <X>100</X> <VerticalAlignment>Bottom</VerticalAlignment> <Height>50</Height> <Width>100</Width> <Text>This is a test button...</Text> </Button> <Window Name="Window1" Namespace="DigitalRune.Game.UI.Controls"> <Content> <StackPanel Name="Panel0"> <Children> <TextBox Name="TextBox0"> <Text>Default text</Text> </TextBox> <TextBox Name="TextBox1"> <Text>Default text</Text> </TextBox> </Children> </StackPanel> </Content> </Window> </Layout>
The XML file can contain any types of classes. The types must be defined in the this assembly or in an assembly referenced by the Assemblies list. Properties of the objects can be specified in XML attributes or in XML elements. Each type can have a Namespace attribute. For example, if the XML above is loaded, an instance of NamespaceFoo1.Foo2.MyClass is created. If no namespace attribute is specified, the DefaultNamespace of the root node Layout is used.
Properties that are lists (interface IList) are also supported, see Window.Children in the example above. The collection property (e.g. Window.Children) is not initialized by the LayoutSerializer, the LayoutSerializer will only try to add items to the collection.
The LayoutSerializer can be used with an XDocument and with a XmlReader. Only the later is available in portable class library builds for .NET 4.0.