Reading array of Rectangles from XML

Started by
2 comments, last by Dave Hunt 11 years ago

I'm bit confused why do I have to format array of Rectangles like this:


        <SourceRect>
          0 0 48 36
          48 0 48 36
        </SourceRect>

...instead of using <item></item> or <Rectangle></Rectangle> tags for each component in array?

I've been using the default method described here to load XML content in to the XNA project:

http://msdn.microsoft.com/en-us/library/ff604979.aspx

Advertisement
See http://blogs.msdn.com/b/shawnhar/archive/2008/08/12/everything-you-ever-wanted-to-know-about-intermediateserializer.aspx - Everything you ever wanted to know about IntermediateSerializer.

That's an optimization applied to certain types of arrays.

See http://blogs.msdn.com/b/shawnhar/archive/2008/08/12/everything-you-ever-wanted-to-know-about-intermediateserializer.aspx - Everything you ever wanted to know about IntermediateSerializer.

That's an optimization applied to certain types of arrays.

Thank you, excactly the information I needed, the built in serializer isn't very well documented.

Now for example I'm deserializing class something like this:


public class SomeDataList
{
    [ContentSerializer]
    private SomeData[] data;

    // public properties and other stuff.

    public SomeDataList()
    {}

    public SomeData GetSomeData(int index)
    {
        // return stuff.
    }
}

If I understood correctly the serializer requires parameterless constructor. Can I just mark this constructor private to only ever create instances of the class during content loading?

Also just to clarify I am correct on this right?


// Both reference the same object.
SomeDataList listFirst = Content.Load<SomeDataList>("ListOne");
SomeDataList listSecond = Content.Load<SomeDataList>("ListOne");

// Two different objects.
SomeDataList listFirst = Content.Load<SomeDataList>("ListOne");
SomeDataList listSecond = Content.Load<SomeDataList>("ListTwo");

Thanks for the help again. :>

A private constructor should work, since IntermediateSerializer user generated IL, rather than C# to do its work.

Yes, your first two statements will reference the same object and the second two will reference different objects.

This topic is closed to new replies.

Advertisement