88
99namespace Nest
1010{
11-
1211 /// <summary>
1312 /// Represents a Latitude/Longitude as a 2 dimensional point that gets serialized as { lat, lon }
1413 /// </summary>
@@ -18,18 +17,16 @@ public class GeoLocation : IEquatable<GeoLocation>, IFormattable
1817 /// Latitude
1918 /// </summary>
2019 [ JsonProperty ( "lat" ) ]
21- public double Latitude => _latitude ;
22- private readonly double _latitude ;
20+ public double Latitude { get ; }
2321
2422 /// <summary>
2523 /// Longitude
2624 /// </summary>
2725 [ JsonProperty ( "lon" ) ]
28- public double Longitude => _longitude ;
29- private readonly double _longitude ;
26+ public double Longitude { get ; }
3027
3128 /// <summary>
32- /// Represents a Latitude/Longitude as a 2 dimensional point.
29+ /// Represents a Latitude/Longitude as a 2 dimensional point.
3330 /// </summary>
3431 /// <param name="latitude">Value between -90 and 90</param>
3532 /// <param name="longitude">Value between -180 and 180</param>
@@ -42,32 +39,26 @@ public GeoLocation(double latitude, double longitude)
4239 if ( ! IsValidLongitude ( longitude ) )
4340 throw new ArgumentOutOfRangeException ( string . Format ( CultureInfo . InvariantCulture ,
4441 "Invalid longitude '{0}'. Valid values are between -180 and 180" , longitude ) ) ;
45- _latitude = latitude ;
46- _longitude = longitude ;
42+ Latitude = latitude ;
43+ Longitude = longitude ;
4744 }
4845
4946 /// <summary>
5047 /// True if <paramref name="latitude"/> is a valid latitude. Otherwise false.
5148 /// </summary>
5249 /// <param name="latitude"></param>
5350 /// <returns></returns>
54- public static bool IsValidLatitude ( double latitude )
55- {
56- return latitude >= - 90 && latitude <= 90 ;
57- }
51+ public static bool IsValidLatitude ( double latitude ) => latitude >= - 90 && latitude <= 90 ;
5852
5953 /// <summary>
6054 /// True if <paramref name="longitude"/> is a valid longitude. Otherwise false.
6155 /// </summary>
6256 /// <param name="longitude"></param>
6357 /// <returns></returns>
64- public static bool IsValidLongitude ( double longitude )
65- {
66- return longitude >= - 180 && longitude <= 180 ;
67- }
58+ public static bool IsValidLongitude ( double longitude ) => longitude >= - 180 && longitude <= 180 ;
6859
6960 /// <summary>
70- /// Try to create a <see cref="GeoLocation"/>.
61+ /// Try to create a <see cref="GeoLocation"/>.
7162 /// Return <value>null</value> if either <paramref name="latitude"/> or <paramref name="longitude"/> are invalid.
7263 /// </summary>
7364 /// <param name="latitude">Value between -90 and 90</param>
@@ -80,18 +71,17 @@ public static GeoLocation TryCreate(double latitude, double longitude)
8071 return null ;
8172 }
8273
83- public override string ToString ( )
84- {
85- return _latitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) + "," + _longitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) ;
86- }
74+ public override string ToString ( ) =>
75+ Latitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) + "," +
76+ Longitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) ;
8777
8878 public bool Equals ( GeoLocation other )
8979 {
9080 if ( ReferenceEquals ( null , other ) )
9181 return false ;
9282 if ( ReferenceEquals ( this , other ) )
9383 return true ;
94- return _latitude . Equals ( other . _latitude ) && _longitude . Equals ( other . _longitude ) ;
84+ return Latitude . Equals ( other . Latitude ) && Longitude . Equals ( other . Longitude ) ;
9585 }
9686
9787 public override bool Equals ( object obj )
@@ -106,7 +96,7 @@ public override bool Equals(object obj)
10696 }
10797
10898 public override int GetHashCode ( ) =>
109- unchecked ( ( _latitude . GetHashCode ( ) * 397 ) ^ _longitude . GetHashCode ( ) ) ;
99+ unchecked ( ( Latitude . GetHashCode ( ) * 397 ) ^ Longitude . GetHashCode ( ) ) ;
110100
111101 public string ToString ( string format , IFormatProvider formatProvider ) => ToString ( ) ;
112102
@@ -117,21 +107,18 @@ public static implicit operator GeoLocation(string latLon)
117107
118108 var parts = latLon . Split ( ',' ) ;
119109 if ( parts . Length != 2 ) throw new ArgumentException ( "Invalid format: string must be in the form of lat,lon" ) ;
120- double lat ;
121- if ( ! double . TryParse ( parts [ 0 ] , NumberStyles . Any , CultureInfo . InvariantCulture , out lat ) )
110+ if ( ! double . TryParse ( parts [ 0 ] , NumberStyles . Any , CultureInfo . InvariantCulture , out var lat ) )
122111 throw new ArgumentException ( "Invalid latitude value" ) ;
123- double lon ;
124- if ( ! double . TryParse ( parts [ 1 ] , NumberStyles . Any , CultureInfo . InvariantCulture , out lon ) )
112+ if ( ! double . TryParse ( parts [ 1 ] , NumberStyles . Any , CultureInfo . InvariantCulture , out var lon ) )
125113 throw new ArgumentException ( "Invalid longitude value" ) ;
126114 return new GeoLocation ( lat , lon ) ;
127115 }
128116
129117 public static implicit operator GeoLocation ( double [ ] lonLat )
130118 {
131- if ( lonLat . Length != 2 )
132- return null ;
133-
134- return new GeoLocation ( lonLat [ 1 ] , lonLat [ 0 ] ) ;
119+ return lonLat . Length != 2
120+ ? null
121+ : new GeoLocation ( lonLat [ 1 ] , lonLat [ 0 ] ) ;
135122 }
136123 }
137124
@@ -141,14 +128,21 @@ public static implicit operator GeoLocation(double[] lonLat)
141128 [ JsonConverter ( typeof ( GeoCoordinateJsonConverter ) ) ]
142129 public class GeoCoordinate : GeoLocation
143130 {
144- public GeoCoordinate ( double latitude , double longitude ) : base ( latitude , longitude )
145- {
146- }
131+ /// <summary>
132+ /// Creates a new instance of <see cref="GeoCoordinate"/>
133+ /// </summary>
134+ public GeoCoordinate ( double latitude , double longitude ) : base ( latitude , longitude ) { }
147135
136+ /// <summary>
137+ /// Creates a new instance of <see cref="GeoCoordinate"/> from a pair of coordinates
138+ /// in the order Latitude then Longitude.
139+ /// </summary>
148140 public static implicit operator GeoCoordinate ( double [ ] coordinates )
149141 {
150142 if ( coordinates == null || coordinates . Length != 2 )
151- throw new ArgumentOutOfRangeException ( nameof ( coordinates ) , "Can not create a GeoCoordinate from an array that does not have two doubles" ) ;
143+ throw new ArgumentOutOfRangeException (
144+ nameof ( coordinates ) ,
145+ $ "Can not create a { nameof ( GeoCoordinate ) } from an array that does not have two doubles") ;
152146
153147 return new GeoCoordinate ( coordinates [ 0 ] , coordinates [ 1 ] ) ;
154148 }
0 commit comments