473,414 Members | 1,776 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,414 software developers and data experts.

how do you ignore inherited members with XMLSerialization?

I have a class which inherits from a generated abstract base class.

I simply want to hide some fields which are inherited from the base
class when it is serialised.

I have tried:

public class Details : GeneratedDetails
{
[XmlIgnore]
public new string Id
{
get{return base.lId;}
set{Id = value;}
}

and:

[XmlIgnore]
public override string Id
{
get{return base.lId;}
set{Id = value;}
}
}

All these do is serialise the base members instead. As the base class
is generated it is no good putting the [XMLIgnore] on the base class
members (although this is what I have had to do for now).

I have Googled extensively but found no examples or answers to this
problem - apart from creating a wrapper class which inherits from my
Details class and only exposes the members I want my visible in the
web service. That will create an immense amount of work as it will
mean replicating a load of methods and derived classes of the Details
class just for the web service and therefore defeating the object of
OO!

Please help!
Nov 12 '05 #1
4 4038
"rob bowley" <ro********@gmail.com> wrote in message news:21**************************@posting.google.c om...
I simply want to hide some fields which are inherited from the base
class when it is serialised. : : As the base class
is generated it is no good putting the [XMLIgnore] on the base class
members (although this is what I have had to do for now).


Why not generate the base class with the XmlIgnoreAttributes on
the base class members? It sounds like you have the source code
to do this, and it's only a text file so it's pretty straightforward to
insert a step in the generation process taking the source code w/o
XmlIgnoreAttribute and adding the XmlIgnoreAttribute auto-
matically.
Derek Harmon
Nov 12 '05 #2
Hi Derek,

Thanks for replying.

I could do that, but then all generated base class members would be
ignored by default and I would then have to override every member I
wished to expose, which would often be quite a lot. It also would mean
re-engineering all existing code that inherits from classes generated
using the template.

However, that is better than what I'm doing at the moment and better
than creating a wrapper.

What I really want to clear up is if there is any way at all of telling
the serializer to ignore members from a base class.

Nov 12 '05 #3
I have the same issue with a web service. A property on a base class is an
IDictionary type which cannot be serialized. Without modifying the base
class' source code, how can I tell the XmlSerializer (and SoapSerializer for
that matter) to ignore this property? I too attempted to override the
property and mark it with XmlIgnore, but obviously that did not work.

Thanks,
Chris

"rob bowley" <ro********@gmail.com> wrote in message
news:21**************************@posting.google.c om...
I have a class which inherits from a generated abstract base class.

I simply want to hide some fields which are inherited from the base
class when it is serialised.

I have tried:

public class Details : GeneratedDetails
{
[XmlIgnore]
public new string Id
{
get{return base.lId;}
set{Id = value;}
}

and:

[XmlIgnore]
public override string Id
{
get{return base.lId;}
set{Id = value;}
}
}

All these do is serialise the base members instead. As the base class
is generated it is no good putting the [XMLIgnore] on the base class
members (although this is what I have had to do for now).

I have Googled extensively but found no examples or answers to this
problem - apart from creating a wrapper class which inherits from my
Details class and only exposes the members I want my visible in the
web service. That will create an immense amount of work as it will
mean replicating a load of methods and derived classes of the Details
class just for the web service and therefore defeating the object of
OO!

Please help!

Nov 12 '05 #4
I now have a few solutions to this proplem.

I created a boolean - IdSpecified - in the base class set to true and
then set it to false in the constructor of the derived class. This hid
the Id property from serialisation as the serialiser recognises this:

http://msdn.microsoft.com/library/de...ClassTopic.asp

However, the solution we are going with is to have all base members set
to XmlIgnore and then override them in the derived class. As the body
of the derived class is also initially generated, all fields will be
overriden so that they are exposed. Then, to hide a member, we simply
delete it from the derived class.

This also helps with changing a property's type in the derived class
(serialisation fails if a property is hiding an inherited property with
a different type) as it will not build unless you delete the generated
overriden property in the derived class.

I still think you should be able to hide an inherited property from the
derived class without manipulating the base class.

Thanks,

Rob

Nov 12 '05 #5

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

Similar topics

1
by: sam | last post by:
Hi Doesn't seem like XMLSerialization serializes Shared properties. My vb.net class has a load of properties, only two of which are marked as Shared. When I serialize it to XML, all the...
0
by: Jax | last post by:
Just to confirm. If I have object foo: public class foo { private string myPrivate; protected string myProtected; public string myPublic; public class foo()
1
by: skootr | last post by:
I have a Public Interface defined in a class module. I also have a form that implements that interface After building the solution, I added an Inherited Form (inherited from the above-mentioned...
6
by: rob.bowley | last post by:
I have a class which inherits from a generated abstract base class. I simply want to hide some fields which are inherited from the base class when it is serialised. I have tried: public...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
2
by: lovecreatesbeauty | last post by:
I'm disturbed on this question on a long time. I think if I finally get understand it with your kind help, I will get close to a excellent C++ programmer. And I only can rely on your expertise and...
14
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming...
19
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit...
2
by: eggie5 | last post by:
Hi, I have a class Dog which derives from Animal. Suppose my instance of Dog is bulldog. bulldog has all the members of Animal plus Dog. How can copy just the members from Dog to a new Dog...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.