Thoughts from Dan Miser RSS 2.0
# Wednesday, January 10, 2007
XML serialization is handy, but it does lack some power. For example, if you have class inheritance, and you want a property of the child class to have a different name than the one given to it by the parent, you will get an error at run-time when trying to serialize the object: "Member 'Derived.Name' hides inherited member 'Base.Name', but has different custom attributes.".

Assume you have a class structure like this:

public abstract class Base

{

    private int id;

    private string name;

 

    [XmlElement("id")]

    public int Id

    {

        get { return id; }

        set { id = value; }

    }

 

    [XmlElement("name")]

    public virtual string Name

    {

        get { return name; }

        set { name = value; }

    }

}

 

public class Derived : Base

{

    [XmlElement("newName")]

    public override string Name

    {

        get { return base.Name; }

        set { base.Name = value; }

    }

}

To see the error, call it like this:

static void Main(string[] args)

{

    Derived d = new Derived();

    d.Id = 23;

    d.Name = "Dan";

    string xml = GetXMLFromObject(d);

    Console.WriteLine(xml);

}

Download the sample application here to play with it.

Wednesday, January 10, 2007 5:57:12 PM (GMT Standard Time, UTC+00:00)  #    Comments [1] -
.NET | XML
Tracked by:
http://fbbbbbbbbbbbb.com [Pingback]
http://dbbbbbbbbbbbb.com [Pingback]
http://bbbbbbbbbbcc.com [Pingback]
http://ebbbbbbbbbbbb.com [Pingback]
http://bbbbbbbbbbbbc.com [Pingback]
http://www.dogs.com [Pingback]
http://www.cats.de [Pingback]
http://9nn-information.info/29385313/index.html [Pingback]
http://9nr-information.info/00186259/index.html [Pingback]
http://9nn-information.info/35854442/index.html [Pingback]
http://9nj-information.info/00912371/hotel-bakpak-sydney.html [Pingback]
http://9nn-information.info/09897099/oxford-health-nj-membership.html [Pingback]
http://9nw-information.info/94666699/index.html [Pingback]
http://9nn-information.info/67656280/index.html [Pingback]
http://9nl-information.info/77817267/index.html [Pingback]
http://9nb-information.info/93023239/toontown-internet-interruption.html [Pingback]
http://9nk-information.info/28103486/index.html [Pingback]
http://9nq-information.info/19989711/index.html [Pingback]
http://9oj-information.info/80803365/business-e-marketing-plan.html [Pingback]
http://9ou-information.info/70506437/index.html [Pingback]
http://9qf-information.info/36899623/index.html [Pingback]
http://9oy-information.info/67707659/nursing-home-company.html [Pingback]
http://9ok-information.info/90188528/index.html [Pingback]
http://9rf-information.info/14309502/index.html [Pingback]
http://9rk-information.info/33174511/index.html [Pingback]
http://9rs-information.info/68454610/index.html [Pingback]
http://9sk-information.info/95937220/index.html [Pingback]
http://9so-information.info/41473092/mostra-box-doccia.html [Pingback]
http://9st-information.info/60980750/index.html [Pingback]
http://9rt-information.info/07138644/index.html [Pingback]
http://9uaff-le-informazioni.info/98922698/index.html [Pingback]
http://9uaef-le-informazioni.info/05586901/index.html [Pingback]
http://9uaer-le-informazioni.info/80931383/index.html [Pingback]
http://9uafn-le-informazioni.info/86483994/index.html [Pingback]
http://9uafa-le-informazioni.info/24836104/index.html [Pingback]
http://9uaea-le-informazioni.info/93012950/index.html [Pingback]
http://9uafs-le-informazioni.info/84149221/index.html [Pingback]
http://9uaef-le-informazioni.info/32740313/www-rai-clik.html [Pingback]
http://9uagj-le-informazioni.info/99784610/index.html [Pingback]
http://9uahj-le-informazioni.info/71195905/index.html [Pingback]
http://9uagr-le-informazioni.info/39884300/flash-caratteri.html [Pingback]
http://9uagi-le-informazioni.info/71413890/index.html [Pingback]
http://9uahr-le-informazioni.info/54579871/index.html [Pingback]
http://9uage-le-informazioni.info/55106701/ordine-ingegneri-venezia.html [Pingback]
http://9uagt-le-informazioni.info/93757630/frame-capture.html [Pingback]
http://9uago-le-informazioni.info/59038757/evelyn-lau.html [Pingback]
Navigation
Archive
<November 2014>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)