c# - XMLSerializer : Ignoring Elements in List -


i got fine working xmlserializer sophisticated list of 3d models many different elements. want serialize list beside of that, saving few elements of it. tried bar of them out [xmlignore] causes problems in deserialization of other list.

here's code of (de)serializer:

public void serializeobject<t>(t serializableobject, string filename) {     if (serializableobject == null) return;      var serializer = new xmlserializer(serializableobject.gettype());      using (var stream = file.open(filename, filemode.create))     {         serializer.serialize(stream, serializableobject);     } }  public t deserializeobject<t>(string filename) {      if (string.isnullorempty(filename)) return default(t);      var serializer = new xmlserializer(typeof(t),overrides);      using (var stream = file.open(filename, filemode.open))     {         return (t)serializer.deserialize(stream);     } } 

maybe idea clone list, , remove elements don't wish save before serialization?

you can use base derived relation build collection type 1 ignore serialization , other override ignored.

[serializable] public abstract class baseclass {     [xmlignore]     public virtual bool basemember { get; set; }  }  [serializable] public class derivedclass : baseclass {     public string derivedmember { get; set; } }  [serializable] public class xmlignore : baseclass {     // no xmlignore     public override bool basemember     {                 {             return base.basemember;         }         set         {             base.basemember = value;         }     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -