473,378 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

XmlSerialization, inheritance and attribute overriding.

Ian
I've got this problem with overriding attributes on an inheritance
chain where the XmlSerializer is concerned. For example:

public class A
{
private string aWord = String.Empty();

[System.Xml.Serialization.XmlElementAttribute("a-word")]
public virtual string Word { get { return aWord; } set { aWord =
value; } }
}

public class B : A
{
[System.Xml.Serialization.XmlElementAttribute("b-word")]
public override string Word { get { return base.Word; } set {
base.Word = value; } }
... Other stuff...
}

The idea here is that when I serialize an instance of A, I want the
element corresponding to the Word property to show up as "<a-word>"
but when I serialize an instance of B, I want to have that property
serialized as "<b-word>". When the XmlSerializer goes to serialize
it, I get the following:

System.InvalidOperationException: Member 'B.Word' hides inherited
member 'A.Word', but has different custom attributes.

I've also tried making a new property that access the old one and
telling it to ignore the inherited one, but it still serializes the
inherited one anyway, which I dont want. for example:

public class B : A
{
[System.Xml.Serialization.XmlElementAttribute("b-word")]
public virtual string NewWord { get { return base.Word; } set {
base.Word = value; } }

[System.Xml.Serialization.XmlIgnoreAttribute()]
public override string Word { get { return base.Word; } set {
base.Word = value; } }

}

This yields two elements (one a-word and one b-word.) I want to hide
the a-word all together.

Now I've done a bunch of work with the design time components where
overriding declarative attributes on inheritance is common practice.
And furthermore I dont think this is a language problem. Is this just
not possible? Obviously I can reflect on it just prior to
serialization and remove the attributes at runtime, but the nicest
part of the XmlSerialization is that you can do all this stuff
declaratively, and not have to do a ton of footwork. Am I expecting
too much?

Ian
Nov 11 '05 #1
0 5669

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
1
by: Tony Johansson | last post by:
Hello! Private inheritance is sometimes called implementation inheritance. If you use this private inheritance how is with the usage of overriding then. Is overriding used less often when...
0
by: Craig Edmunds | last post by:
I'm having problems serializing an object & can't find a way around it. I have 2 classes Public Class SessionBase Private _testString As String Public Property TestString() As String Get
4
by: Mark Sizer | last post by:
Hi people, I'm having trouble trying to achieve something in C# and win forms, and am looking for a little advice if anyone has a moment. I've got two classes: 1) a base class 2) a derived...
0
by: A programmer desperatly needing help! | last post by:
I use the xmlserialization on asp.net pages and on previous machines it never gave a problem. But now i somethings get a: Timed out waiting for a program to execute. The command being executed was...
5
by: Chris Szabo | last post by:
Good afternoon everyone. I'm running into a problem deserializing a stream using the XmlSerializer. A stored procedure returns the following from SQL Server: <Student StudentId="1" Status="1"...
6
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
4
by: vivekian | last post by:
Hi, Have this following hierarchy which am implementing for a networking program. The base class 'ASocket' is the base class from which 'AListener' and 'ATalker' inherit . None of the functions...
3
by: LW | last post by:
Hi! I am getting the following error message for my fairly simple web service. I have classes and have two DataSets that reference the same classes. The error is: The XML element named...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.