/// <summary> /// Converts a string to a Duration 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> /// <remarks>Copy of WebConvert.TryKeyStringToTime.</remarks> private static bool TryUriStringToDuration(string text, out TimeSpan targetValue) { if (!UriParserHelper.TryRemoveLiteralPrefix(ExpressionConstants.LiteralPrefixDuration, ref text)) { targetValue = default(TimeSpan); return(false); } if (!UriParserHelper.TryRemoveQuotes(ref text)) { targetValue = default(TimeSpan); return(false); } try { targetValue = EdmValueParser.ParseDuration(text); return(true); } catch (FormatException) { targetValue = default(TimeSpan); return(false); } }
/// <summary> /// Try to parse the given text to a Geometry object. /// </summary> /// <param name="text">Text to parse.</param> /// <param name="targetValue">Geometry to return.</param> /// <param name="parsingFailureReasonException">The detailed reason of parsing error.</param> /// <returns>True if succeeds, false if not.</returns> private static bool TryUriStringToGeometry(string text, out Geometry targetValue, out UriLiteralParsingException parsingFailureReasonException) { parsingFailureReasonException = null; if (!UriParserHelper.TryRemoveLiteralPrefix(ExpressionConstants.LiteralPrefixGeometry, ref text)) { targetValue = default(Geometry); return(false); } if (!UriParserHelper.TryRemoveQuotes(ref text)) { targetValue = default(Geometry); return(false); } try { targetValue = LiteralUtils.ParseGeometry(text); return(true); } catch (ParseErrorException e) { targetValue = default(Geometry); parsingFailureReasonException = new UriLiteralParsingException(e.Message); 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> /// <remarks>Copy of WebConvert.TryKeyStringToByteArray.</remarks> private static bool TryUriStringToByteArray(string text, out byte[] targetValue) { Debug.Assert(text != null, "text != null"); if (!UriParserHelper.TryRemoveLiteralPrefix(ExpressionConstants.LiteralPrefixBinary, ref text)) { targetValue = null; return(false); } if (!UriParserHelper.TryRemoveQuotes(ref text)) { targetValue = null; return(false); } try { targetValue = Convert.FromBase64String(text); } catch (FormatException) { targetValue = null; return(false); } return(true); }