コード例 #1
0
        /// <summary>
        /// Parse a text to a GPS location.
        /// </summary>
        /// <param name="text">the text to parse</param>
        /// <param name="format">the format to use, to determine the decimal separator</param>
        /// <param name="result">the parsed GPS location</param>
        internal static bool TryParse(string text, NumberFormatInfo format, out GpsLocation result)
        {
            var parser = new GpsLocationParser(text, format);
            var parsed = parser.Execute();

            result = parsed.Item2;
            return(parsed.Item1);
        }
コード例 #2
0
        /// <summary>
        /// Convert a textual representation of a GPS location to an actual GPS location.
        /// This will throw an exception when the text could not be parsed.
        /// </summary>
        /// <param name="text">the text to be parsed</param>
        /// <param name="format">the format to use, to determine the decimal separator</param>
        /// <returns>a valid GPS location. When the text could not be parsed an exception is thrown</returns>
        public static GpsLocation Parse(string text, NumberFormatInfo format)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentOutOfRangeException(nameof(text));
            }

            if (!GpsLocationParser.TryParse(text, format, out GpsLocation result))
            {
                throw new ArgumentOutOfRangeException(nameof(text));
            }
            return(result);
        }
コード例 #3
0
 /// <summary>
 /// Try to create a GPS location from the given text
 /// </summary>
 /// <param name="text">the text to parse</param>
 /// <param name="result">the parsed location</param>
 /// <param name="format">the format to use</param>
 /// <returns>whether the parsing was successful</returns>
 public static bool TryParse(string text, NumberFormatInfo format, out GpsLocation result)
 {
     return(GpsLocationParser.TryParse(text, format, out result));
 }