Tinibou:So I have the following classes :
- XXX
- XXXContent
- XXXWriter : ContentTypeWriter<XXXContent>
- XXXReader : ContentTypeReader<XXX>
Does it seem correct for you ?
Looks right to me.
Tinibou:
You also said that "if I wanted to use this pattern (...)" does it mean that this is not the only way to do it (I know that I could sequentially read my XML) ? Which is the best way ? Using pairs of classes each time ?
Sorry, I didn't mean to imply that there was a better way :) As with most coding problems, there is probably another way to do what you're doing. The pattern of runtime/design-time class pairs is pretty tried and true in the content pipeline. I'd recommend sticking with it.
Tinibou:
Shawn also mentionned partial classes but I can't see where it helps because you must have two object types here ?
What Shawn suggests is that you could have a partial class defined in both the content pipeline and in your main game assembly. Let's say thats in Foo.cs. Then, you could have Foo's run-time specific stuff in a file called FooRuntime.cs, which would add additional functionality. If necessary, design-time specific stuff could be in a file called FooDesigntime.cs, which is only added to the content pipeline assembly. This may not be the best pattern for your game, though - you'll have to decide that for yourself.
Tinibou:
And another question if I may ask :) Is there a way to define classes attributes as optional in the reading/writing process ? I mean, I know the [ContentSerializerIgnore] tag but can I write my XML so that I could "omit" a tag and the class attribute would be null ? And if the tag exists, the value is correctly retrieved ?
I'm not sure what you're trying to do. Could you be more specific? Are you trying to change the way your XML is read into the content pipeline during a build, or are you trying to change the way the final binary asset is written and loaded?