Re: Deserialize method that "loads" the class instance itself: how???
From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 05/14/04
- Next message: John Young: "Re: Launching IE from a Winform"
- Previous message: Jon Skeet [C# MVP]: "Re: StreamWriter closes MemoryStream???"
- In reply to: Bob Rock: "Re: Deserialize method that "loads" the class instance itself: how???"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 May 2004 09:30:36 -0400
Bob,
Why not do this. Get the schema for the XML and then run the XSD.exe
tool against it. This will create a C# file which is a class (which might
derive from DataSet if you say so) that you can compile in your app. Then,
you can use the ReadXml method on the DataSet (if you choose to have your
class derive from that), or the Deserialize method on the XmlSerializer
class to deserialize an instance of the class in your app.
Once you have that, you can do anything you want with the class, or have
a containing class use it for whatever purposes you wish.
Hope this helps.
"Bob Rock" <nospam.yet_another_apprentice@hotmail.com> wrote in message
news:eyYzFJbOEHA.2944@TK2MSFTNGP10.phx.gbl...
> "Dennis Myrén" <dennis@oslokb.no> wrote in message
> news:AB2pc.1462$RL3.32889@news2.e.nsc.no...
> > I would implement a static method in the class that is serializable,
like:
> >
> > public static YourClass Deserialize ( Stream fromStream )
> > {
> > XmlSerializer serializer = new XmlSerializer(typeof(YourClass));
> > return (YourClass) serializer.Deserialize(stream);
> > }
>
> Dannis, that is what I will do if I can't find an easy way to do it with
an
> instance method.
>
> Bob Rock
>
>
>
- Next message: John Young: "Re: Launching IE from a Winform"
- Previous message: Jon Skeet [C# MVP]: "Re: StreamWriter closes MemoryStream???"
- In reply to: Bob Rock: "Re: Deserialize method that "loads" the class instance itself: how???"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|