@@ -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,36 +52,19 @@ 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
- /// <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
-
95
68
public override string ToString ( ) =>
96
69
Latitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) + "," +
97
70
Longitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) ;
@@ -157,6 +130,8 @@ public GeoCoordinate(double latitude, double longitude, double z) : base(latitud
157
130
/// <summary>
158
131
/// Creates a new instance of <see cref="GeoCoordinate" /> from an array
159
132
/// 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>
160
135
/// </summary>
161
136
public static implicit operator GeoCoordinate ( double [ ] coordinates )
162
137
{
@@ -168,11 +143,11 @@ public static implicit operator GeoCoordinate(double[] coordinates)
168
143
return new GeoCoordinate ( coordinates [ 0 ] , coordinates [ 1 ] ) ;
169
144
case 3 :
170
145
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") ;
171
150
}
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
151
}
177
152
}
178
153
}
0 commit comments