/// <summary>Converts a string to a GUID value.</summary>
        /// <param name="text">String text to convert.</param>
        /// <param name="targetValue">After invocation, converted value.</param>
        /// <returns>true if the value was converted; false otherwise.</returns>
        private static bool TryKeyStringToGuid(string text, out Guid targetValue)
        {
            if (!DomainDataServiceQueryStringConverter.TryRemoveLiteralPrefix(TypeUtils.LiteralPrefixGuid, ref text))
            {
                targetValue = default(Guid);
                return(false);
            }

            if (!DomainDataServiceQueryStringConverter.TryRemoveQuotes(ref text))
            {
                targetValue = default(Guid);
                return(false);
            }

            try
            {
                targetValue = XmlConvert.ToGuid(text);
                return(true);
            }
            catch (FormatException)
            {
                targetValue = default(Guid);
                return(false);
            }
        }
        /// <summary>Converts a string to a DateTime value.</summary>
        /// <param name="text">String text to convert.</param>
        /// <param name="targetValue">After invocation, converted value.</param>
        /// <returns>true if the value was converted; false otherwise.</returns>
        private static bool TryKeyStringToDateTime(string text, out DateTime targetValue)
        {
            if (!DomainDataServiceQueryStringConverter.TryRemoveLiteralPrefix(TypeUtils.LiteralPrefixDateTime, ref text))
            {
                targetValue = default(DateTime);
                return(false);
            }

            if (!DomainDataServiceQueryStringConverter.TryRemoveQuotes(ref text))
            {
                targetValue = default(DateTime);
                return(false);
            }

            try
            {
                targetValue = XmlConvert.ToDateTime(text, XmlDateTimeSerializationMode.RoundtripKind);
                return(true);
            }
            catch (FormatException)
            {
                targetValue = default(DateTime);
                return(false);
            }
        }
        /// <summary>Converts a string to a byte[] value.</summary>
        /// <param name="text">String text to convert.</param>
        /// <param name="targetValue">After invocation, converted value.</param>
        /// <returns>true if the value was converted; false otherwise.</returns>
        private static bool TryKeyStringToByteArray(string text, out byte[] targetValue)
        {
            Debug.Assert(text != null, "text != null");

            if (!DomainDataServiceQueryStringConverter.TryRemoveLiteralPrefix(TypeUtils.LiteralPrefixBinary, ref text) &&
                !DomainDataServiceQueryStringConverter.TryRemoveLiteralPrefix(TypeUtils.XmlBinaryPrefix, ref text))
            {
                targetValue = null;
                return(false);
            }

            if (!DomainDataServiceQueryStringConverter.TryRemoveQuotes(ref text))
            {
                targetValue = null;
                return(false);
            }

            if ((text.Length % 2) != 0)
            {
                targetValue = null;
                return(false);
            }

            byte[] result      = new byte[text.Length / 2];
            int    resultIndex = 0;
            int    textIndex   = 0;

            while (resultIndex < result.Length)
            {
                char ch0 = text[textIndex];
                char ch1 = text[textIndex + 1];
                if (!DomainDataServiceQueryStringConverter.IsCharHexDigit(ch0) ||
                    !DomainDataServiceQueryStringConverter.IsCharHexDigit(ch1))
                {
                    targetValue = null;
                    return(false);
                }

                result[resultIndex] = (byte)((byte)(DomainDataServiceQueryStringConverter.HexCharToNibble(ch0) << 4) +
                                             DomainDataServiceQueryStringConverter.HexCharToNibble(ch1));
                textIndex += 2;
                resultIndex++;
            }

            targetValue = result;
            return(true);
        }