?
Solved

Serialiization of an object that inherit from a tabpage object.

Posted on 2010-01-12
4
Medium Priority
?
555 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:yaron89
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:DaveJellison
ID: 26300562
What information do you need to serialize inside of the tabpage control itself? Do you know this before-hand or only at runtime?
0
 

Author Comment

by:yaron89
ID: 26301630
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
 
LVL 4

Accepted Solution

by:
DaveJellison earned 2000 total points
ID: 26301695
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question