Loads/saves objects from/to a XML file. (Currently, only loading objects is implemented!)

Namespace: DigitalRune.Game.UI
Assembly: DigitalRune.Game.UI (in DigitalRune.Game.UI.dll) Version: 1.1.0.0 (1.1.1.9392)

Syntax

C#
public class LayoutSerializer
Visual Basic
Public Class LayoutSerializer
Visual C++
public ref class LayoutSerializer

Remarks

The Load(XContainer) method reads an XML document, creates and returns the objects specified in the XML document. Here is an example XML file:

Examples

C# Copy imageCopy
<?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.

Inheritance Hierarchy

System..::..Object
  DigitalRune.Game.UI..::..LayoutSerializer

See Also