Click or drag to resize
DigitalRuneLayoutSerializer Class
Loads/saves objects from/to a XML file. (Currently, only loading objects is implemented!)
Inheritance Hierarchy
SystemObject
  DigitalRune.Game.UILayoutSerializer

Namespace: DigitalRune.Game.UI
Assembly: DigitalRune.Game.UI (in DigitalRune.Game.UI.dll) Version: 1.8.0.0 (1.8.0.14553)
Syntax
public class LayoutSerializer

The LayoutSerializer type exposes the following members.

Constructors
  NameDescription
Public methodLayoutSerializer
Initializes a new instance of the LayoutSerializer class
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodLoad(XContainer)
Loads the objects specified in the given XML container.
Public methodLoad(XmlReader)
Loads the objects specified in the given XML container.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnCreateInstance(Type, XElement)
Called when a game instance needs to be created.
Protected methodOnCreateInstance(Type, XmlReader)
Called when a game instance needs to be created.
Protected methodOnGetType(XElement)
Called to find a type for the given XML element.
Protected methodOnGetType(XmlReader)
Called to find a type for the given XML element.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyAssemblies
Gets assemblies that contain the types.
Protected propertyDefaultNamespace
Gets or sets the default namespace specified in the "Layout" node of the XML file.
Top
Remarks

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

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

See Also