public static bool TryParse(string inputString, out PositionalDegree positionalDegree) { try { positionalDegree = Parse(inputString); return(true); } catch (Exception) { positionalDegree = null; return(false); } }
//======================================================================= #endregion //======================================================================= //======================================================================= #region -= static methods =- /// <summary> /// Must be in the format 24952.32,N;45612.85,W /// </summary> /// <param name="inputString"></param> /// <returns></returns> public static Position Parse(string inputString) { //---- declare vars Position position = new Position(); string[] halves = inputString.Split(';'); if (halves.Length < 2) { throw new FormatException(); } position.Latitude = PositionalDegree.Parse(halves[0]); position.Longitude = PositionalDegree.Parse(halves[1]); //---- return(position); }
//======================================================================= #endregion //======================================================================= //======================================================================= #region -= static methods =- /// <summary> /// must be in the format 24952.32,N /// </summary> /// <param name="positionalDegree"></param> /// <returns></returns> public static PositionalDegree Parse(string inputString) { //---- declare vars PositionalDegree position = new PositionalDegree(); //---- split it in half string[] halves = inputString.Trim().Split(','); //---- if (halves.Length < 2) { throw new FormatException("Input string must be in the format 23490.32,N"); } //---- parse the direction position.Direction = DirectionUtil.Parse(halves[1]); //---- parse the degrees, minutes seconds decimal degrees; bool isparse = true; try { degrees = decimal.Parse(halves[0]); } catch (ArgumentException) { isparse = false; degrees = new decimal(); } if (isparse) { position.Degrees = degrees; } else { throw new FormatException("Degrees must be in the format 20934.23"); } //---- return(position); }