/// <summary>Converts the string into a Location.</summary> /// <param name="value"> /// A string containing a co-ordinate to convert. /// </param> /// <param name="style"> /// A combination of allowable styles that value can be formatted to. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about /// the input string. /// </param> /// <returns> /// A Location that is equivalent to the value specified in value. /// </returns> /// <exception cref="ArgumentNullException">value is null.</exception> /// <exception cref="FormatException"> /// value does not represent a valid co-ordinate. /// </exception> public static Location Parse(string value, LocationStyles style = LocationStyles.None, IFormatProvider provider = null) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (TryParse(value, style, provider, out var output)) { return(output); } throw new FormatException(); }
/// <summary>Converts the string into a Location.</summary> /// <param name="value"> /// A string containing a co-ordinate to convert. /// </param> /// <param name="style"> /// A combination of allowable styles that value can be formatted to. /// </param> /// <param name="provider"> /// An object that supplies culture-specific formatting information about /// the input string. /// </param> /// <param name="location"> /// Contains the converted value, if the conversion succeeded, or null /// if the conversion failed. This parameter is passed uninitialized. /// </param> /// <returns> /// true if the value was converted successfully; otherwise, false. /// </returns> public static bool TryParse(string value, LocationStyles style, IFormatProvider provider, out Location location) { location = null; if (style == LocationStyles.None) { style = LocationStyles.Degrees | LocationStyles.DegreesMinutes | LocationStyles.DegreesMinutesSeconds; } if ((style & LocationStyles.Iso) != 0) { location = Parser.ParseIso(value); if (location != null) { return(true); } } if ((style & LocationStyles.DegreesMinutesSeconds) != 0) { location = Parser.ParseDegreesMinutesSeconds(value, provider); if (location != null) { return(true); } } if ((style & LocationStyles.DegreesMinutes) != 0) { location = Parser.ParseDegreesMinutes(value, provider); if (location != null) { return(true); } } if ((style & LocationStyles.Degrees) != 0) { location = Parser.ParseDegrees(value, provider); if (location != null) { return(true); } } return(location != null); }