title: C# DataContract Serialization, how to deserialize to already existing instance
body: <p>I have a class, which holds a static dictionary of all existing instances, which are defined at compile time.</p>
  
  <p>Basically it looks like this:</p>
  
  <pre><code>[DataContract]
  class Foo
  {
    private static Dictionary&lt;long, Foo&gt; instances = new Dictionary&lt;long, Foo&gt;();
  
    [DataMember]
    private long id;
  
    public static readonly Foo A = Create(1);
    public static readonly Foo B = Create(2);
    public static readonly Foo C = Create(3);
  
    private static Foo Create(long id)
    {
      Foo instance = new Foo();
      instance.id = id;
      instances.Add(instance);
      return instance;
    }
  
    public static Foo Get(long id)
    {
      return instances[id];
    }    
  
  }
  </code></pre>
  
  <p>There are other fields, and the class is derived, but this doesn't matter for the problem.</p>
  
  <p>Only the <code>id</code> is serialized. When an instance of this type is deserialized, I would like to get the instance that has been created as the static field (<code>A</code>, <code>B</code> or <code>C</code>), using <code>Foo.Get(id)</code> instead of getting a new instance.</p>
  
  <p>Is there a simple way to do this? I didn't find any resources which I was able to understand.</p>