Exemplo n.º 1
0
        public object ParseDateTime(XmlNode node, Type valueType, ParseStack parseStack)
        {
            if (valueType.IsNoDateTime())
            {
                throw new XmlRpcTypeMismatchException(parseStack.ParseType + " contains dateTime.iso8601 value where " + XmlRpcServiceInfo.GetXmlRpcTypeString(valueType) + " expected " + parseStack.Dump());
            }

            parseStack.Push("dateTime");
            try
            {
                var child = node.FirstChild;
                if (child == null)
                {
                    if (_config.MapEmptyDateTimeToMinValue())
                    {
                        return(DateTime.MinValue);
                    }
                    else
                    {
                        throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType + " contains empty dateTime value " + parseStack.Dump());
                    }
                }

                var datestring = child.Value;

                if (!DateTime8601.TryParseDateTime8601(datestring, out var retVal))
                {
                    if (_config.MapZerosDateTimeToMinValue() &&
                        datestring.StartsWith("0000") &&
                        (datestring == "00000000T00:00:00" || datestring == "0000-00-00T00:00:00Z" || datestring == "00000000T00:00:00Z" || datestring == "0000-00-00T00:00:00"))
                    {
                        retVal = DateTime.MinValue;
                    }
                    else
                    {
                        throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType + " contains invalid dateTime value " + parseStack.Dump());
                    }
                }

                return(valueType == typeof(XmlRpcDateTime) ? new XmlRpcDateTime(retVal) : (object)retVal);
            }
            finally
            {
                parseStack.Pop();
            }
        }