@@ -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,36 +52,19 @@ 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
78- /// <summary>
79- /// 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.
83- /// </summary>
84- /// <param name="latitude">Value between -90 and 90</param>
85- /// <param name="longitude">Value between -180 and 180</param>
86- /// <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- }
94-
9568 public override string ToString ( ) =>
9669 Latitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) + "," +
9770 Longitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) ;
@@ -157,6 +130,8 @@ public GeoCoordinate(double latitude, double longitude, double z) : base(latitud
157130 /// <summary>
158131 /// Creates a new instance of <see cref="GeoCoordinate" /> from an array
159132 /// of 2 or 3 doubles, in the order Latitude, Longitude, and optional Z value.
133+ /// Returns null if coordinates are null
134+ /// <exception cref="ArgumentOutOfRangeException">If the array does not contain 2 or 3 values</exception>
160135 /// </summary>
161136 public static implicit operator GeoCoordinate ( double [ ] coordinates )
162137 {
@@ -168,11 +143,11 @@ public static implicit operator GeoCoordinate(double[] coordinates)
168143 return new GeoCoordinate ( coordinates [ 0 ] , coordinates [ 1 ] ) ;
169144 case 3 :
170145 return new GeoCoordinate ( coordinates [ 0 ] , coordinates [ 1 ] , coordinates [ 2 ] ) ;
146+ default :
147+ throw new ArgumentOutOfRangeException (
148+ nameof ( coordinates ) ,
149+ $ "Cannot create a { nameof ( GeoCoordinate ) } from an array that does not contain 2 or 3 values") ;
171150 }
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") ;
176151 }
177152 }
178153}
0 commit comments