Monday, March 26, 2012

Serializable

Hello,

I have a class with various properties: strings, integers, controls, etc.

I made this class serializable using:

[Serializable]public class Employee...

My question is:

Can I do this when I have properties of type control?

What data types can my class properties have?

Thanks,

Miguel

Control type itself isn't serializable so it won't serialize even if the class having the property (of Control type) is marked serializable. By default all primitive types (integers, strings etc) are serializable but then with other types it is based on if the class is serializable (at least has serializable attribute applied and optionally implements ISerializable or IXmlSerializable interfaces).

More information:
Basics of .NET Framework Serialization
http://msdn2.microsoft.com/en-us/ms233836(VS.80).aspx


And what about object type?

Basically, I am creating a class which has a property as follows:

Private Box As Generic.List(Of Object)

Now I am adding strings, or booleans, or integers or other basic types to this Generic List (I think it should be of type object since I would like to use various types).

Then I want to serialize it and save it in the SQL database. Later I will retrieve it.

Is this possible?

Thanks,

Miguel


Generic List itself is serializable so as long as those objects you put to the List are serializable, things work fine.Serializability of the real type (of added object) is what matters.

Just note that if you use XML serialization, private members won't be serialized (only public members and properties).


If I use a property which type is a structure that has properties of strings and integers.

Is this serializable?

Thanks,

Miguel


Yes

0 comments:

Post a Comment