![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
Senior Member
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
|
Code:
a simple class structure.. now lets create a world with two spheres Code:
and now, we want to save this as xml.. how could we do that? yes: Code:
and the result? voilą: Code:
you want the name and position as xml attribute instead? so add meta-attributes to your classes. like this: Code:
result: Code:
thats about it.. loading should be rather intuitive now, shouldn't it? ![]() well.. what else do you need? exactly: Code:
and that was it. have fun!
___________________________________________
davepermen.net -Loving a Person is having the wish to see this Person happy, no matter what that means to yourself. -No matter what it means to myself.... |
|
|
|
|
#2 |
|
Senior Member
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
|
okay.. i've played a bit with inheritance now, too.. here's what i got:
i added a subtype to sphere, namely sun Code:
and changed our second sphere to be a sun: Code:
and got an exception now. they are well documented (right in the exception ), so i learned i have to include the type to the xml serializer.. so i did.. like that:Code:
this tells that Sphere will possibly have a subclass of type Sun. written that attribute, it compiles and runs fine.
___________________________________________
davepermen.net -Loving a Person is having the wish to see this Person happy, no matter what that means to yourself. -No matter what it means to myself.... |
|
|
|
|
#3 |
|
DevMaster Staff
Join Date: Apr 2003
Location: Germany
Posts: 2,328
|
hey... thank you for that !!!
i got the same exception yesterday at 11pm, after we talked about the stuff. i appears the exception doesn't turn up when you write inherited data, so i was confused and postponed the thing. i was to write a code snippet, too. well, maybe if i find out a few other cool things ![]()
___________________________________________
If Prolog is the answer, what is the question ? |
|
|
|
|
#4 |
|
Senior Member
Join Date: Jan 2003
Location: Switzerland
Posts: 1,333
|
i'm currently testing out other ways to collect the information on what inherited class types exist..
one way is to scan the array for it's types, and collect them, and pass as additional parameter to XmlSerializer.. like this: Code:
(yeah, i know, a bit long, you can collect directly into an array, too, but you will have doubles/tribles, then.. wich i didn't wanted to). a next thing, wich could be interesting, is to scan the whole World class, or possibly some type for all findable inherited classes.. with help of the reflection namespace.. if nothing else, i at least learn more about c# and the .NET framework, hehe ![]() oh, and, generics rock! ![]()
___________________________________________
davepermen.net -Loving a Person is having the wish to see this Person happy, no matter what that means to yourself. -No matter what it means to myself.... |
|
|
|
|
#5 |
|
New Member
Join Date: Feb 2006
Location: The Islamic Republic of England
Posts: 7
|
What happens if you have a class like a graph?
Code:
A node can - and usually is - connected to more than one edge. But AFAICT C# can't tell the difference between a reference and an instance, so If I serialize as illustrated above I get a f**ked up graph. (My custom serialiser converts node references to integer indices and saves these to get around this). |
|
|
|
|
#6 |
|
DevMaster Staff
Join Date: Jan 2003
Location: Mars
Posts: 1,141
|
please don't resurrect old posts.
___________________________________________
baldurk He who knows not and knows that he knows not is ignorant. Teach him. He who knows not and knows not that he knows not is a fool. Shun him. |
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|