• Advertisement
Sign in to follow this  

Reading array of Rectangles from XML

This topic is 1736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

 

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. :>

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement