Something which I really hate is to cast each element or attribute value from a Xml file.
This momment, I'm creating in hundreds of modules a methods where specifies how to convert an object into a XmlFile. Believe, this is very tired. So I'm thinking in an alternative.
I was investigating about XSD, I'm not sure if this will be my salvation. I'm using Linq to Xml to save and get the values. I mean, my objects are composed like this:
- Foo1 : Foo
- Range1 : Range
- X : int
- Y : int
- ...
As you can see, they have many nodes. Is there another alternative to do this? I mean, strongly types.
You can try these XElement extension methods: http://searisen.com/xmllib/extensions.wiki
Here is an example of the power of it, given this xml from another post:
This sets the value of the UpgradeImage tag's SourceFile Attribute and the TargetImage tag inside the UpgradeImage and its SourceFile.
You can also get their values in the same fashion (no casts).
Or this can be written as:
To get a list of integers:
Use the GetEnumerable() method:
To set a new list of ints:
Which results in this new xml: