Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Folk,
i got a fine working XMLSerializer for a sophisticated List of 3D model with many different elements. Now i want to serialize another List beside of that, that only saves few Elements of it. I just tried to bar some of them out with [XMLIgnore] but this causes problems in my deserialization. My plan is now to tag the attributes he should save. Could somebody give me a hint?

Heres the Code of my Serializer.
C#
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)
     {
         XmlAttributeOverrides overrides = new XmlAttributeOverrides();
         XmlAttributes attributes = new XmlAttributes();
         attributes.XmlIgnore = false;

         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);
         }
     }


I got attributes in the root of my List that i want to extract (and even more important, large number of elements that i want to remove) , aswell in sublists.

big thanks.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900