private object MapDateTime(string value, Type valType, MappingStack mappingStack,
                            MappingAction mappingAction, out Type mappedType)
 {
     CheckExpectedType(valType, typeof(DateTime), mappingStack);
     mappedType = typeof(DateTime);
     return(OnStack("dateTime", mappingStack, delegate()
     {
         if (value == "" && MapEmptyDateTimeToMinValue)
         {
             return DateTime.MinValue;
         }
         DateTime retVal;
         if (!DateTime8601.TryParseDateTime8601(value, out retVal))
         {
             if (MapZerosDateTimeToMinValue && value.StartsWith("0000") &&
                 (value == "00000000T00:00:00" || value == "0000-00-00T00:00:00Z" ||
                  value == "00000000T00:00:00Z" || value == "0000-00-00T00:00:00"))
             {
                 retVal = DateTime.MinValue;
             }
             else
             {
                 throw new XmlRpcInvalidXmlRpcException(mappingStack.MappingType
                                                        + " contains invalid dateTime value "
                                                        + StackDump(mappingStack));
             }
         }
         return retVal;
     }));
 }
Exemple #2
0
        private DateTime ParseDateTime(string value, MappingStack mappingStack)
        {
            if (value == string.Empty && MapEmptyDateTimeToMinValue)
            {
                return(DateTime.MinValue);
            }

            DateTime retVal;

            if (DateTime8601.TryParseDateTime8601(value, out retVal))
            {
                return(retVal);
            }

            if (MapZerosDateTimeToMinValue &&
                value.StartsWith("0000", StringComparison.Ordinal) &&
                (string.Equals(value, "00000000T00:00:00", StringComparison.Ordinal) ||
                 string.Equals(value, "0000-00-00T00:00:00Z", StringComparison.Ordinal) ||
                 string.Equals(value, "00000000T00:00:00Z", StringComparison.Ordinal) ||
                 string.Equals(value, "0000-00-00T00:00:00", StringComparison.Ordinal)))
            {
                return(DateTime.MinValue);
            }

            throw new XmlRpcInvalidXmlRpcException(
                      string.Format(
                          "{0} contains invalid dateTime value {1}",
                          mappingStack.MappingType,
                          StackDump(mappingStack)));
        }