title: How to pass custom data to deserialization function
body: <p>I'm doing some C# IO work and I want to import/export data from a few classes.
  After looking for a while, it seems serialization is pretty close to what I want.</p>
  
  <p>However, there is a problem. I have a XML file that describes members of a certain class(which I will refer as <code>ValueWithId</code>), which are aggregated in a class which I will call <code>CollectionOfValuesWithId</code> for the purposes of this question.</p>
  
  <p><code>ValueWithId</code> is a class that contains a <code>string</code> member called <code>ShortName</code>, which is unique. There is only one <code>ShortName</code> per <code>ValueWithId</code> and all <code>ValueWithId</code> have a non-null <code>ShortName</code>. <code>CollectionOfValuesWithId</code> contains a function to find the <code>ValueWithId</code> with a given <code>ShortName</code>.</p>
  
  <p>When serializing, I do <em>NOT</em> want to store <code>ValueWithId</code> nor <code>CollectionOfValuesWithId</code> in the output file. Instead, I just want to store the <code>ShortName</code> in the file.
  So far, so good. I just need to use <code>SerializationInfo.AddValue("ValueWithId", MyValueWIthId.ShortName)</code>.</p>
  
  <p>The problem comes with deserialization. Some googling suggests that to read data from a file one would do this:</p>
  
  <pre><code>public SomeClassThatUsesValueWithId(SerializationInfo info, StreamingContext ctxt)
  {
      string name = (string)info.GetValue("ValueWithId", typeof(string));
  }
  </code></pre>
  
  <p>However, the string is not enough to recover the <code>ValueWithId</code> instance. I also need the <code>CollectionOfValuesWithId</code>. I want something like this:</p>
  
  <pre><code>public SomeClassThatUsesValueWithId(SerializationInfo info,
     StreamingContext ctxt, CollectionOfValuesWithId extraParameter)
  </code></pre>
  
  <p>In other words, I need to pass extra data to the deserialization constructor. Does anyone know any way to do this or any alternatives?</p>