コード例 #1
0
ファイル: LiteralParser.cs プロジェクト: zdzislaw/odata.net
            /// <summary>
            /// Tries to parse the literal by first removing required formatting for the expected type, then converting the resulting string.
            /// </summary>
            /// <param name="text">String text to convert.</param>
            /// <param name="targetType">Type to convert string to.</param>
            /// <param name="targetValue">After invocation, converted value.</param>
            /// <returns>true if the value was converted; false otherwise.</returns>
            private static bool TryRemoveFormattingAndConvert(string text, Type targetType, out object targetValue)
            {
                Debug.Assert(text != null, "text != null");
                Debug.Assert(targetType != null, "expectedType != null");
                Debug.Assert(!targetType.IsSpatial(), "Not supported for spatial types, as they cannot be part of a key, etag, or skiptoken");

                Debug.Assert(Parsers.ContainsKey(targetType), "Unexpected type: " + targetType);
                PrimitiveParser parser = Parsers[targetType];

                if (!parser.TryRemoveFormatting(ref text))
                {
                    targetValue = null;
                    return(false);
                }

                return(parser.TryConvert(text, out targetValue));
            }