Deserialize method that "loads" the class instance itself: how???
From: Bob Rock (nospam.yet_another_apprentice_at_hotmail.com)
Date: 05/14/04
- Next message: Dennis Myrén: "Re: StreamWriter closes MemoryStream???"
- Previous message: Dennis Myrén: "Re: When to define static constructors and when are they implicitly called???"
- Next in thread: Dennis Myrén: "Re: Deserialize method that "loads" the class instance itself: how???"
- Reply: Dennis Myrén: "Re: Deserialize method that "loads" the class instance itself: how???"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 14 May 2004 13:57:33 +0200
Hello,
I've got an xml stream that I'd need to deserialize into an instance of a
given class A. I'd like to create an instance method on class A (method
Deserialize) that takes this XML stream as input and deserializes it "into
itself" ... in other words I'd like it to "fill" the instance of class A on
which the method has been called instead of returning another instance of
class A.
The code below gives a good idea of what I'd like:
public class A
{
public void Deserialize(MemoryStream stream)
{
XmlSerializer serializer = new XmlSerializer(typeof(A));
// the following line of code obviously does not work since this is
readonly
// but it gives a good idea of what I'd like to do
this = serializer.Deserialize(stream);
}
}
How can I accomplish this without having to manually "load" all the class
fields???
Bob Rock
- Next message: Dennis Myrén: "Re: StreamWriter closes MemoryStream???"
- Previous message: Dennis Myrén: "Re: When to define static constructors and when are they implicitly called???"
- Next in thread: Dennis Myrén: "Re: Deserialize method that "loads" the class instance itself: how???"
- Reply: Dennis Myrén: "Re: Deserialize method that "loads" the class instance itself: how???"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|