Serialiization of an object that inherit from a tabpage object.

In my winform app. I have to serialize an object that inherit from TabPage object.
I got a message that I have to mark the TabPage as [Serializable] too.
How can I do this?
[Serializable] 
    partial class myTabPage : TabPage
    {
        public string ContainerTableTag;
        public bool showAlways;
        public bool showForAllChildren;
        public bool showForChild;
       
        public myTabPage()
        {
           InitializeComponent();           
        }
    }

Open in new window

yaron89Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DaveJellisonCommented:
What information do you need to serialize inside of the tabpage control itself? Do you know this before-hand or only at runtime?
0
yaron89Author Commented:
Hi,
The information I need is some boolean and strings varaibles in myTabPage.
The values accepted only at runtime.
I can try to  seperate the varaibles to another class, however I would like to know if there ia an option to serialize the control as it is, or not.
Thanks.
 
0
DaveJellisonCommented:
You can't really serialize/deserialize controls as-is because of the nature of the beast. Controls have things that change at run time like windows handles, etc. and things that change at design time such as you changing the width of that textbox in the designer. Serialization is not all "all-or-nothing" approach though so I can understand what you want to do. You're trying to serialize what makes sense...your properties such as
        public string ContainerTableTag;
        public bool showAlways;
        public bool showForAllChildren;
        public bool showForChild;
..and that's a perfectly good approach. Unfortunately, since this isn't a control you have total control over because of your inheritance of TabPage you can't (easily) inject a [Serializable] attribute into the TabPage control itself because, obviously you don;t have the source code.

What you can do rather than writing a separate class to contain your properties is inherit the ISerializable interface in your myTabPage and by implementing that interface you can "choose" what and how you want to serialize in your class (and leave the rest alone)

http://www.codeproject.com/KB/cs/objserial.aspx

is a good first-look at using ISerializable and should help you out with the few properties that you need to serialize. Let me know if you need any further assistance with the sample.

Happy Coding


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yaron89Author Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.