Yeah,
After looking at it a bit harder I've decided to just construct classes that
hold the deserialized class as a private member.
much easier.
thanks for confirming that.
"Christoph Schittko [MVP]" wrote:
[color=blue]
> You have to be careful with Inheritance and the XmlSerializer.
>
> You have to instantiate the XmlSerializer instance for the derived type,
> not the base type. However, you can't deserialize the XML documents of
> your base type with that serializer any longer as that serializer
> expects a different root element for the derived type.
>
> You're much better off not changing the generated classes or deriving
> from them when you need to work with the XmlSerializer. Can you design
> classes to operate on the serialization classes instead?
>
> HTH,
> Christoph Schittko
> MVP XML
>
http://weblogs.asp.net/cschittko
>
>[color=green]
> > -----Original Message-----
> > From: Peter Bates [mailto:PeterBates@discussions.microsoft.com]
> > Posted At: Sunday, January 23, 2005 6:05 PM
> > Posted To: microsoft.public.dotnet.xml
> > Conversation: Inheriting from XSDObjectGen classes and XmlSerialize
> > Subject: Inheriting from XSDObjectGen classes and XmlSerialize
> >
> > Hi,
> >
> > I'm just getting used to XSDObjectGen and i have the following[/color]
> question.[color=green]
> > Can i use a class inherited from a class generated by XSDObjectGen[/color]
> with[color=green]
> > XmlSerialize?
> >
> > Specifically, I have many xml files arriving from a PC inventory[/color]
> scanner[color=green]
> > we
> > use.
> > I wish to deserialize them and then process them.
> >
> > I've used XSDObjectGen and XmlSerialize.Deserialize to do this, and[/color]
> it[color=green]
> > works really well.
> >
> > However, for the next step I want to create a set of classes that[/color]
> provide[color=green]
> > functionality on top of the class produced by[/color]
> XmlSerialize.Deserialize.[color=green]
> >
> > I could create these classes and make the XSDObjectGen generated[/color]
> class a[color=green]
> > private memeber, but I'd prefer to inherit from the generated class.
> >
> > Whenever i try to do this, i get exceptions from[/color]
> XmlSerialize.Deserialize.[color=green]
> >
> > The code that works is below
> >
> > XmlSerializer s = new XmlSerializer(typeof(HatLib.HatXml.ScanData));
> > HatLib.HatPc scanData = (HatLib.HatXml.ScanData)s.Deserialize(new
> > XmlTextReader(fileName));
> >
> > However, when i create a class as follows
> >
> > public class HatPc : HatLib.HatXml.ScanData
> > {
> > public HatPc()
> > {
> > }
> > // Specific code here
> >
> > }
> >
> > I can't use this class with XmlSerialize.Deserialize. I've tried many
> > combinations of casting etc to see if i can make it work, but to no[/color]
> avail.[color=green]
> >
> > Any suggestions?
> >
> > Thanks[/color]
>
>[/color]