Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to serialize a custom object aggregating other custom objects
    primarykey
    data
    text
    <p>I'm trying to serialize a custom object into a file. i've tried many thing but no one works, i must have missed a thing.</p> <p>Here's the problem.</p> <p>I have a singleton class i'm using to store my objects. Here is the code : </p> <pre><code>using DataLibrary.Model.Tests; using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization; using System.Xml.Serialization; using testsPsychotechniques.View; namespace testsPsychotechniques.Model { [Serializable()] public class testSaver : ISerializable { private String lastName; private String firstName; private List&lt;ITest&gt; tests; public static testSaver Instance { get { return Nested.instance; } } public void addTest(ITest test) { tests.Add(test); } public Boolean save() { try { FileStream file = File.Open(".\\result.data", FileMode.Create, FileAccess.ReadWrite, FileShare.None); XmlSerializer serializer = new XmlSerializer(typeof(testSaver)); serializer.Serialize(file, testSaver.Instance); file.Close(); return true; } catch { return false; } } private testSaver() { this.firstName = Identification.firstName; this.lastName = Identification.lastName; this.tests = new List&lt;ITest&gt;(); } private class Nested { internal static readonly testSaver instance = new testSaver(); } public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("lastName", this.lastName); info.AddValue("firstName", this.firstName); info.AddValue("testsResults", this.tests); } } } </code></pre> <p>Now the real problem : </p> <p>When i'm calling the save method, in the xml file generated i only have this data :</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;testSaver xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt; </code></pre> <p>The classes implementing the <code>ITest</code> interface are all marked serializable and have a method getObjectData.</p> <p>Another hint is that the functions getObjectData are never used.</p> <p>Thanks for any help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload