I have a somewhat complicated Class that may or may not contain a list of items of the same type
Class Items
{
List<Items> SubItems ...
}
The class itself is serializeable, however its going to be a giant waste of space to serialize the objects in the list since they are serialized and added to the database prior to being included in the list.
Is there a way that I can specify that the list should be represented as a list of integers when its serialized ?
Note: These integers will represent primary keys of the rows where the serialized object is located.
Is there a way that I can specify that the list should be represented as a list of integers when its serialized?
Yep. There are two main options:
1) Implement the ISerializable-Interface, where you can control how the object will be serialized / deserialized.
OR
2) Declare your List as [NonSerialized] and also manage a private Member List, which contains your primary keys. You will have to implement the logic for loading / storing the Integer-List by your own, though.
If your class to serialize is quite big, I would recommend you the second approach, because in the other case you have to manually serialize / deserialize each property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With