@@ -18,18 +18,8 @@ public class GeoLocation : IEquatable<GeoLocation>, IFormattable
1818 /// <summary>
1919 /// Represents a Latitude/Longitude as a 2 dimensional point.
2020 /// </summary>
21- /// <param name="latitude">Value between -90 and 90</param>
22- /// <param name="longitude">Value between -180 and 180</param>
23- /// <exception cref="ArgumentOutOfRangeException">If <paramref name="latitude" /> or <paramref name="longitude" /> are invalid</exception>
2421 public GeoLocation ( double latitude , double longitude )
2522 {
26- if ( ! IsValidLatitude ( latitude ) )
27- throw new ArgumentOutOfRangeException ( string . Format ( CultureInfo . InvariantCulture ,
28- "Invalid latitude '{0}'. Valid values are between -90 and 90" , latitude ) ) ;
29- if ( ! IsValidLongitude ( longitude ) )
30- throw new ArgumentOutOfRangeException ( string . Format ( CultureInfo . InvariantCulture ,
31- "Invalid longitude '{0}'. Valid values are between -180 and 180" , longitude ) ) ;
32-
3323 Latitude = latitude ;
3424 Longitude = longitude ;
3525 }
@@ -62,35 +52,27 @@ public bool Equals(GeoLocation other)
6252 public string ToString ( string format , IFormatProvider formatProvider ) => ToString ( ) ;
6353
6454 /// <summary>
65- /// True if <paramref name="latitude" /> is a valid latitude. Otherwise false .
55+ /// Checks if <paramref name="latitude" /> is a valid latitude between -90 and 90, inclusive .
6656 /// </summary>
6757 /// <param name="latitude"></param>
6858 /// <returns></returns>
6959 public static bool IsValidLatitude ( double latitude ) => latitude >= - 90 && latitude <= 90 ;
7060
7161 /// <summary>
72- /// True if <paramref name="longitude" /> is a valid longitude. Otherwise false .
62+ /// Checks if <paramref name="longitude" /> is a valid longitude between -180 and 180, inclusive .
7363 /// </summary>
7464 /// <param name="longitude"></param>
7565 /// <returns></returns>
7666 public static bool IsValidLongitude ( double longitude ) => longitude >= - 180 && longitude <= 180 ;
7767
7868 /// <summary>
7969 /// Try to create a <see cref="GeoLocation" />.
80- /// Return
81- /// <value>null</value>
82- /// if either <paramref name="latitude" /> or <paramref name="longitude" /> are invalid.
8370 /// </summary>
84- /// <param name="latitude">Value between -90 and 90 </param>
85- /// <param name="longitude">Value between -180 and 180 </param>
71+ /// <param name="latitude"></param>
72+ /// <param name="longitude"></param>
8673 /// <returns></returns>
87- public static GeoLocation TryCreate ( double latitude , double longitude )
88- {
89- if ( IsValidLatitude ( latitude ) && IsValidLongitude ( longitude ) )
90- return new GeoLocation ( latitude , longitude ) ;
91-
92- return null ;
93- }
74+ // TODO: Remove in 8.0 as without bounds checks, provides no value
75+ public static GeoLocation TryCreate ( double latitude , double longitude ) => new GeoLocation ( latitude , longitude ) ;
9476
9577 public override string ToString ( ) =>
9678 Latitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) + "," +
@@ -157,6 +139,8 @@ public GeoCoordinate(double latitude, double longitude, double z) : base(latitud
157139 /// <summary>
158140 /// Creates a new instance of <see cref="GeoCoordinate" /> from an array
159141 /// of 2 or 3 doubles, in the order Latitude, Longitude, and optional Z value.
142+ /// Returns null if coordinates are null
143+ /// <exception cref="ArgumentOutOfRangeException">If the array does not contain 2 or 3 values</exception>
160144 /// </summary>
161145 public static implicit operator GeoCoordinate ( double [ ] coordinates )
162146 {
@@ -168,11 +152,11 @@ public static implicit operator GeoCoordinate(double[] coordinates)
168152 return new GeoCoordinate ( coordinates [ 0 ] , coordinates [ 1 ] ) ;
169153 case 3 :
170154 return new GeoCoordinate ( coordinates [ 0 ] , coordinates [ 1 ] , coordinates [ 2 ] ) ;
155+ default :
156+ throw new ArgumentOutOfRangeException (
157+ nameof ( coordinates ) ,
158+ $ "Cannot create a { nameof ( GeoCoordinate ) } from an array that does not contain 2 or 3 values") ;
171159 }
172-
173- throw new ArgumentOutOfRangeException (
174- nameof ( coordinates ) ,
175- $ "Cannot create a { nameof ( GeoCoordinate ) } from an array that does not contain 2 or 3 values") ;
176160 }
177161 }
178162}
0 commit comments