/// <summary> /// Parse a string into a DistanceSpan /// </summary> /// <param name="distance">String of valid numeric characters</param> /// <param name="distanceType">Type of distance represents (miles, feet, etc)</param> /// <param name="result">Newly created DistanceSpan if successful</param> /// <returns>True if parsing was successful.</returns> public static bool TryParse(string distance, DistanceSpan.DistanceType distanceType, out DistanceSpan result) { try { result = new DistanceSpan(double.Parse(distance, CultureInfo.InvariantCulture), distanceType); } catch { result = DistanceSpan.Zero; return(false); } return(true); }
/// <summary> /// Subtract a distance from this DistanceSpan /// </summary> /// <param name="value">Value to shorten DistanceSpan by</param> /// <param name="distanceType">Type of distance value represents (miles, feet, etc)</param> /// <returns>New DistanceSpan</returns> public DistanceSpan Subtract(double value, DistanceSpan.DistanceType distanceType) { return(this.Add(value * -1D, distanceType)); }
/// <summary> /// Add a value to this span /// </summary> /// <param name="value">Distance to add</param> /// <param name="distanceType">Type of distance to add (kilometers, miles, inches)</param> /// <returns>New span that is sum of current and parameter</returns> public DistanceSpan Add(double value, DistanceSpan.DistanceType distanceType) { return(new DistanceSpan(_meters + ToMetric(value, distanceType))); }
/// <summary> /// Convert a distance from one type to another /// </summary> /// <param name="value">Distance to convert</param> /// <param name="inputType">Type that value represents</param> /// <param name="outputType">Target type the return value represents</param> /// <returns>Converted distance that is of outputType</returns> public static double Convert(double value, DistanceSpan.DistanceType inputType, DistanceType outputType) { return(FromMetric(ToMetric(value, inputType), outputType)); }
/// <summary> /// Constructor to create a distance span /// </summary> /// <param name="value">Value of distance length</param> /// <param name="distanceType">Type of distance value represents (miles, meters, yards, etc.)</param> public DistanceSpan(double value, DistanceSpan.DistanceType distanceType) { _meters = ToMetric(value, distanceType); _countryCode = string.Empty; }