I have an C# object that hold a big list (10-100MB) and some other properties. I want to serialize the object, but I don't want to serialize the list. is there any easy way to do that?
Thanks!
I have an C# object that hold a big list (10-100MB) and some other properties. I want to serialize the object, but I don't want to serialize the list. is there any easy way to do that?
Thanks!
Since it is tagged xml, this could be as simple as adding [XmlIgnore] to the appropriate property:
[XmlIgnore]
public List<Foo> Items {get;set;}
Then just use XmlSerializer as normal.
If it needs to be controllable (sometimes yes, sometimes no) then an alternative is to add:
public bool ShouldSerializeItems() {
// your logic here
}
This pattern is recognised by many serializers, XmlSerializer included.
*Specified (for the appropriate named member).If you mean by serialization loading the object from database, then I can recommend NHibernate, you simply mark, you want to enable lazy-loading on the List and your object will return, with Items set to null (and if you are still in transaction, Items will load, after and only after attempting to access it; if you are out of transaction already, you will get a nullPointer exception I think)... but basically, Lazy-loading in any its kind is certainly a principle, you should keep an eye on.
EDIT: missed the tags, shame on me