Guessing Object Type while Deserializing
<p>I have a few objects serialized <em>[edit: using BinaryFormatter]</em> this way</p>

<pre><code>Obj_A 1    
Obj_A 2
Obj_A 3
Obj_B 1
Obj_B 2
Obj_B 3
Obj_B 4
</code></pre>

<p>How many A objects there are before B's is decided by user on Runtime.</p>

<p>While deserializing, I have no way to guess when to switch form Obj_A deseriliazing to Obj_B</p>

<p>I welcome any relevant insight</p>

<p><em>EDIT :</em> Serialization occurs on the flow and numbers of A's and B's is not known beforehand</p>

<p><strong>ANSWER</strong><br>
Marc Gravell suggested something I was JUST NOT aware of : <br>
Why bother at all ? Just let the formatter do the job and test types afterwards.<br>
(I am surprised I was not massively aswered that by people here, so obvious...)</p>

<pre><code>IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("X:\\binary.dump", FileMode.Open);
object o = formatter.Deserialize(stream);

if (o.GetType() == typeof(Obj_A))
     ReadTheMSDN(Obj_A);

else if (o.GetType() == typeof(Obj_B))
     KnowObjectsYouHandle(Obj_B);

stream.Close();
</code></pre>

<p>Another less elegant solution was to force objects to Lists : </p>

<pre><code>LIST Obj_A
    Obj_A 1    
    Obj_A 2
    Obj_A 3

LIST Obj_B
    Obj_B 1
    Obj_B 2
    Obj_B 3
    Obj_B 4
</code></pre>
