Click here to Skip to main content
13,044,766 members (46,101 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 29 Jul 2011

Get rid of XmlInclude when using XmlSerializer

, 29 Jul 2011
Rate this:
Please Sign up or sign in to vote.
How would you do this, if objects included inside one of the serialized objects was an abstract class? E.g.:abstract class Base{ public int x;}class A : Base{ public int y;}class B : A{ public int z;}class SomeOtherClass{ public string...

How would you do this, if objects included inside one of the serialized objects was an abstract class? E.g.:

abstract class Base
    public int x;
class A : Base
    public int y;
class B : A
    public int z;
class SomeOtherClass
    public string s;
class SerializingClass
    public int w;
    public Base myB1;
    public Base myB2;
//AND you have an object
var sc = new SerializingClass{
   w = 10,
   myB1 = new B{ x = 1, y, 2, z = 3},
   myB2 = new A{ x = 10, y=20 }

How would you use your method to add just Base, A, B, and not SomeOtherClass without knowing the inner classes and derived classes held within your top level class which you request the serializer from? If you must know all of this, then I'd feel that this method is limited to shallow class structs and the XML attribute method works better (for this case).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bob Sandberg
Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralHmm, maybe I just don't get it: OP wrote: typeof(Car).IsAssi... Pin
johannesnestler11-Aug-11 3:27
memberjohannesnestler11-Aug-11 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 29 Jul 2011
Article Copyright 2011 by Bob Sandberg
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid