HealthServiceDateTime throws an argument exception when comparing to non date types RRS feed

  • Question

  • HealthServiceDateTime throws an argument exception in the CompareTo method when the object passed in is not of type  HealthServiceDateTime or DateTime.

    This is problematic for Generic Serializers which check for cyclic references using object comparison. 

    Please fix this to return "false"/"not equal" (non zero return code) as opposed to throwing an exception. 

    Sunday, March 16, 2014 3:14 AM


  • Looking at .NET's implementation of CompareTo on their DateTime object:

        public int CompareTo(object value)
          if (value == null)
            return 1;
          if (!(value is DateTime))
            throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDateTime"));
          long internalTicks1 = ((DateTime) value).InternalTicks;
          long internalTicks2 = this.InternalTicks;
          if (internalTicks2 > internalTicks1)
            return 1;
          return internalTicks2 < internalTicks1 ? -1 : 0;

    They seem to also throw an exception if the object you're comparing to is not of the same type.  We were following the convention to throw like the .NET framework does.

    Monday, March 17, 2014 11:22 PM