Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[XmlIgnore] decorator not working for derived class

Status
Not open for further replies.

jrenae

Programmer
Joined
Jan 18, 2006
Messages
142
Location
US
Hello,

I have a property in my base class that I need serialized when using the base class.

But in my derived class I do not want it serialized. So I in my base class I made it virtual. Then in my derived class I used the decorator [XmlIgnore], but when I serialize my derived class it still includes the property.

Is there any way around this?

Thanks

base class property
Code:
        public virtual int Intent
        {
            get { return this._intent; }
            set { this._intent = value; }
        }

derived class property
Code:
        [XmlIgnore]
        public override int Intent
        { 
            get {return this._intent;}
            set { this._intent = value; }
        }
 
What difference does it make if it is serialized?

C
 
We need it serialized for the base class. But for the derived class, I really only want a subset of the properties. Currently, it is serializing it in my derived class, but I have to put extra logic in on a display page to NOT show the unnecessary properties.
 
Then I would throw a NotSupportedException.

C
 
Or better......

Have BOTH classes you're referring to derive from an abstract class with an abstract Intent property. In one, put the serializing behaviour, in the other the NotSupported.

Then have a factory to decide which one is to be instantiated.

C
 
The reason I say this is that you must be relying on a concrete class somewhere. Program to the interface, not the concrete.

BTW, [XmlIgnore] is not a decorator. It is an attribute. Decorator pattern ( could be used by if you wrapped your base class in another with the same interface and used the wrapper to provide the NotSupported functionality.

C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top