title: hooking into the deserialization process
body: <p>I have a <code>DateRange</code> object that represents the notion of Infinity via Static reference as shown below. As you see, the end points that define Infinity are also static references in a different class, <code>DatePoint.Past</code> and <code>DatePoint.Future</code>.</p>
  
  <p>Now I need to serialize this (as part of a deep Clone method that uses serialization) and know <strong>when it's deserialized that an instance with <code>DateTime.Min</code> and <code>DateTime.Max</code> as endpoints then the instance should be <code>DateRange.Infinity</code></strong>. So I think I need to make it <code>ISerializable</code>.</p>
  
  <p>My first attempt at implementing <code>ISerializable</code> is quite poor; and but I'm showing it in the hopes it suggests a quicker fix to someone. I have used some similar code for NHibernate to store <code>DateRange</code> in the db and reconstitue Infinity, but I'm not getting how to apply that for serialization yet.</p>
  
  <p><code>DatePoint</code> is marked <code>[Serializable]</code> but does not implement <code>ISerializable</code>.</p>
  
  <h1>edited question</h1>
  
  <p>I am not looking to serialize/deserialize Infinity. What I <em>am</em> looking for is a hook into where I can take the deserialized <code>DataRange</code> and decide if it is equivalent to <code>Infinity</code>.</p>
  
  <h1>**</h1>
  
  <p>Cheers,
  Berryl</p>
  
  <h1>DateRange</h1>
  
  <pre><code>[Serializable]
  [TypeConverter(typeof(DateRangeTypeConverter))]
  public class DateRange : ValueObject, IRange&lt;DatePoint, DateRange, TimeSpan&gt;, ISerializable
  {
      /// &lt;summary&gt;
      /// Returns a range spanning &lt;see cref="DatePoint.Past"/&gt; and &lt;see cref="DatePoint.Future"/&gt;.
      /// &lt;/summary&gt;
      public static readonly DateRange Infinity = new DateRange(DatePoint.Past, DatePoint.Future);
  
  
      /// &lt;summary&gt; The start of the &lt;see cref="DateRange"/&gt; range. &lt;/summary&gt;
      public DatePoint Start { get; protected set; }
  
      /// &lt;summary&gt; The end of the &lt;see cref="DateRange"/&gt; range. &lt;/summary&gt;
      public DatePoint End { get; protected set; }
  
  }
  </code></pre>
  
  <h1>DatePoint</h1>
  
  <pre><code>public class DatePoint : ValueObject, IComparable&lt;DatePoint&gt;, IComparable&lt;DateTime&gt;, IComparable, IEquatable&lt;DatePoint&gt;, IEquatable&lt;DateTime&gt;, IFormattable
  {
  
      /// &lt;summary&gt;The undefined infinite past, smaller than any other date except itself.&lt;/summary&gt;
      public readonly static DatePoint Past = DateTime.MinValue;
  
      /// &lt;summary&gt;The undefined infinite future, larger than any other date except itself.&lt;/summary&gt;
      public readonly static DatePoint Future = DateTime.MaxValue;
  
  }
  </code></pre>
  
  <h1>First ISerializable attempt</h1>
  
  <pre><code>    protected DateRange(SerializationInfo info, StreamingContext ctx) {
          if (info == null)
              throw new System.ArgumentNullException("info");
          var start = (DatePoint)info.GetValue("Start", typeof(DatePoint));
          var end = (DatePoint)info.GetValue("End", typeof(DatePoint));
          // its Infinity if so
          if((start.Equals(DatePoint.Past) &amp;&amp; end.Equals(DatePoint.Future)))
              return;
      }
  
      public void GetObjectData(SerializationInfo info, StreamingContext context)
      {
      }
  </code></pre>