@@ -18,18 +18,8 @@ public class GeoLocation : IEquatable<GeoLocation>, IFormattable
18
18
/// <summary>
19
19
/// Represents a Latitude/Longitude as a 2 dimensional point.
20
20
/// </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>
24
21
public GeoLocation ( double latitude , double longitude )
25
22
{
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
-
33
23
Latitude = latitude ;
34
24
Longitude = longitude ;
35
25
}
@@ -62,35 +52,27 @@ public bool Equals(GeoLocation other)
62
52
public string ToString ( string format , IFormatProvider formatProvider ) => ToString ( ) ;
63
53
64
54
/// <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 .
66
56
/// </summary>
67
57
/// <param name="latitude"></param>
68
58
/// <returns></returns>
69
59
public static bool IsValidLatitude ( double latitude ) => latitude >= - 90 && latitude <= 90 ;
70
60
71
61
/// <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 .
73
63
/// </summary>
74
64
/// <param name="longitude"></param>
75
65
/// <returns></returns>
76
66
public static bool IsValidLongitude ( double longitude ) => longitude >= - 180 && longitude <= 180 ;
77
67
78
68
/// <summary>
79
69
/// 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
70
/// </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>
86
73
/// <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 ) ;
94
76
95
77
public override string ToString ( ) =>
96
78
Latitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) + "," +
@@ -157,6 +139,8 @@ public GeoCoordinate(double latitude, double longitude, double z) : base(latitud
157
139
/// <summary>
158
140
/// Creates a new instance of <see cref="GeoCoordinate" /> from an array
159
141
/// 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>
160
144
/// </summary>
161
145
public static implicit operator GeoCoordinate ( double [ ] coordinates )
162
146
{
@@ -168,11 +152,11 @@ public static implicit operator GeoCoordinate(double[] coordinates)
168
152
return new GeoCoordinate ( coordinates [ 0 ] , coordinates [ 1 ] ) ;
169
153
case 3 :
170
154
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") ;
171
159
}
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") ;
176
160
}
177
161
}
178
162
}
0 commit comments