Skip to content

Commit d8bdaa0

Browse files
committed
Refactorings based on microsoft ruleset.
1 parent 80b70fc commit d8bdaa0

34 files changed

Lines changed: 328 additions & 331 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generic C# Geocoding API [![CI](https://github.com/exceptionless/Geocoding.net/actions/workflows/build.yml/badge.svg)](https://github.com/exceptionless/Geocoding.net/actions/workflows/build.yml) [![Publish Packages](https://github.com/exceptionless/Geocoding.net/actions/workflows/publish-packages.yml/badge.svg)](https://github.com/exceptionless/Geocoding.net/actions/workflows/publish-packages.yml) [![CodeQL](https://github.com/exceptionless/Geocoding.net/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/exceptionless/Geocoding.net/actions/workflows/codeql-analysis.yml)
1+
# Generic C# Geocoding API [![CI](https://github.com/exceptionless/Geocoding.net/actions/workflows/build.yml/badge.svg)](https://github.com/exceptionless/Geocoding.net/actions/workflows/build.yml) [![CodeQL](https://github.com/exceptionless/Geocoding.net/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/exceptionless/Geocoding.net/actions/workflows/codeql-analysis.yml)
22

33
Includes a model and interface for communicating with five popular Geocoding providers. Current implementations include:
44

@@ -65,7 +65,7 @@ The Microsoft and Yahoo implementations each provide their own address class as
6565

6666
## API Keys
6767

68-
Google [requires a new Server API Key](https://developers.google.com/maps/documentation/javascript/tutorial#api_key) to access its service.
68+
Google can use a [Server API Key](https://developers.google.com/maps/documentation/javascript/tutorial#api_key), and some environments now require one to access the service reliably.
6969

7070
Bing [requires an API key](http://msdn.microsoft.com/en-us/library/ff428642.aspx) to access its service.
7171

samples/Example.Web/Program.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Geocoding;
1+
using Geocoding;
22
using Geocoding.Google;
33
using Geocoding.Here;
44
using Geocoding.MapQuest;
@@ -219,13 +219,13 @@ static IResult ProviderProblem(string provider, ProviderOptions options, Excepti
219219
return Results.Problem(title: "Geocoding provider request failed.", detail: detail, statusCode: StatusCodes.Status502BadGateway);
220220
}
221221

222-
sealed record GeocodeResponse(string Provider, string Address, AddressResponse[] Results);
222+
internal sealed record GeocodeResponse(string Provider, string Address, AddressResponse[] Results);
223223

224-
sealed record ReverseGeocodeResponse(string Provider, double Latitude, double Longitude, AddressResponse[] Results);
224+
internal sealed record ReverseGeocodeResponse(string Provider, double Latitude, double Longitude, AddressResponse[] Results);
225225

226-
sealed record AddressResponse(string FormattedAddress, string Provider, double Latitude, double Longitude);
226+
internal sealed record AddressResponse(string FormattedAddress, string Provider, double Latitude, double Longitude);
227227

228-
sealed class ProviderOptions
228+
internal sealed class ProviderOptions
229229
{
230230
public GoogleProviderOptions Google { get; init; } = new();
231231
public BingProviderOptions Bing { get; init; } = new();
@@ -234,29 +234,29 @@ sealed class ProviderOptions
234234
public YahooProviderOptions Yahoo { get; init; } = new();
235235
}
236236

237-
sealed class GoogleProviderOptions
237+
internal sealed class GoogleProviderOptions
238238
{
239239
public String ApiKey { get; init; } = String.Empty;
240240
}
241241

242-
sealed class BingProviderOptions
242+
internal sealed class BingProviderOptions
243243
{
244244
public String ApiKey { get; init; } = String.Empty;
245245
}
246246

247-
sealed class HereProviderOptions
247+
internal sealed class HereProviderOptions
248248
{
249249
public String AppId { get; init; } = String.Empty;
250250
public String AppCode { get; init; } = String.Empty;
251251
}
252252

253-
sealed class MapQuestProviderOptions
253+
internal sealed class MapQuestProviderOptions
254254
{
255255
public String ApiKey { get; init; } = String.Empty;
256256
public bool UseOsm { get; init; }
257257
}
258258

259-
sealed class YahooProviderOptions
259+
internal sealed class YahooProviderOptions
260260
{
261261
public String ConsumerKey { get; init; } = String.Empty;
262262
public String ConsumerSecret { get; init; } = String.Empty;

src/Geocoding.Core/Address.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace Geocoding;
66
/// </summary>
77
public abstract class Address
88
{
9-
string formattedAddress = string.Empty;
10-
Location coordinates;
11-
string provider = string.Empty;
9+
private string _formattedAddress = string.Empty;
10+
private Location _coordinates;
11+
private string _provider = string.Empty;
1212

1313
/// <summary>
1414
/// Initializes a new address instance.
@@ -28,13 +28,13 @@ public Address(string formattedAddress, Location coordinates, string provider)
2828
/// </summary>
2929
public virtual string FormattedAddress
3030
{
31-
get { return formattedAddress; }
31+
get { return _formattedAddress; }
3232
set
3333
{
3434
if (string.IsNullOrWhiteSpace(value))
3535
throw new ArgumentException("FormattedAddress is null or blank");
3636

37-
formattedAddress = value.Trim();
37+
_formattedAddress = value.Trim();
3838
}
3939
}
4040

@@ -43,13 +43,13 @@ public virtual string FormattedAddress
4343
/// </summary>
4444
public virtual Location Coordinates
4545
{
46-
get { return coordinates; }
46+
get { return _coordinates; }
4747
set
4848
{
4949
if (value == null)
5050
throw new ArgumentNullException("Coordinates");
5151

52-
coordinates = value;
52+
_coordinates = value;
5353
}
5454
}
5555

@@ -58,13 +58,13 @@ public virtual Location Coordinates
5858
/// </summary>
5959
public virtual string Provider
6060
{
61-
get { return provider; }
61+
get { return _provider; }
6262
protected set
6363
{
6464
if (string.IsNullOrWhiteSpace(value))
6565
throw new ArgumentException("Provider can not be null or blank");
6666

67-
provider = value;
67+
_provider = value;
6868
}
6969
}
7070

@@ -75,7 +75,7 @@ protected set
7575
/// <returns>The distance between the two addresses.</returns>
7676
public virtual Distance DistanceBetween(Address address)
7777
{
78-
return this.Coordinates.DistanceBetween(address.Coordinates);
78+
return Coordinates.DistanceBetween(address.Coordinates);
7979
}
8080

8181
/// <summary>
@@ -86,7 +86,7 @@ public virtual Distance DistanceBetween(Address address)
8686
/// <returns>The distance between the two addresses.</returns>
8787
public virtual Distance DistanceBetween(Address address, DistanceUnits units)
8888
{
89-
return this.Coordinates.DistanceBetween(address.Coordinates, units);
89+
return Coordinates.DistanceBetween(address.Coordinates, units);
9090
}
9191

9292
/// <summary>

src/Geocoding.Core/Bounds.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ namespace Geocoding;
77
/// </summary>
88
public class Bounds
99
{
10-
readonly Location southWest;
11-
readonly Location northEast;
10+
private readonly Location _southWest;
11+
private readonly Location _northEast;
1212

1313
/// <summary>
1414
/// Gets the southwest corner.
1515
/// </summary>
1616
public Location SouthWest
1717
{
18-
get { return southWest; }
18+
get { return _southWest; }
1919
}
2020

2121
/// <summary>
2222
/// Gets the northeast corner.
2323
/// </summary>
2424
public Location NorthEast
2525
{
26-
get { return northEast; }
26+
get { return _northEast; }
2727
}
2828

2929
/// <summary>
@@ -53,8 +53,8 @@ public Bounds(Location southWest, Location northEast)
5353
if (southWest.Latitude > northEast.Latitude)
5454
throw new ArgumentException("southWest latitude cannot be greater than northEast latitude");
5555

56-
this.southWest = southWest;
57-
this.northEast = northEast;
56+
_southWest = southWest;
57+
_northEast = northEast;
5858
}
5959

6060
/// <summary>
@@ -77,7 +77,7 @@ public bool Equals(Bounds bounds)
7777
if (bounds == null)
7878
return false;
7979

80-
return (this.SouthWest.Equals(bounds.SouthWest) && this.NorthEast.Equals(bounds.NorthEast));
80+
return SouthWest.Equals(bounds.SouthWest) && NorthEast.Equals(bounds.NorthEast);
8181
}
8282

8383
/// <summary>
@@ -95,6 +95,6 @@ public override int GetHashCode()
9595
/// <returns>A string representation of the bounds.</returns>
9696
public override string ToString()
9797
{
98-
return string.Format("{0} | {1}", southWest, northEast);
98+
return $"{_southWest} | {_northEast}";
9999
}
100100
}

src/Geocoding.Core/Distance.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ public struct Distance
1515
public const double EarthRadiusInKilometers = 6378.135;
1616
private const double ConversionConstant = 0.621371192;
1717

18-
private readonly double value;
19-
private readonly DistanceUnits units;
18+
private readonly double _value;
19+
private readonly DistanceUnits _units;
2020

2121
/// <summary>
2222
/// Gets the numeric distance value.
2323
/// </summary>
2424
public double Value
2525
{
26-
get { return value; }
26+
get { return _value; }
2727
}
2828

2929
/// <summary>
3030
/// Gets the units of the distance value.
3131
/// </summary>
3232
public DistanceUnits Units
3333
{
34-
get { return units; }
34+
get { return _units; }
3535
}
3636

3737
/// <summary>
@@ -41,8 +41,8 @@ public DistanceUnits Units
4141
/// <param name="units">The units for the value.</param>
4242
public Distance(double value, DistanceUnits units)
4343
{
44-
this.value = Math.Round(value, 8);
45-
this.units = units;
44+
_value = Math.Round(value, 8);
45+
_units = units;
4646
}
4747

4848
#region Helper Factory Methods
@@ -73,16 +73,16 @@ public static Distance FromKilometers(double kilometers)
7373

7474
private Distance ConvertUnits(DistanceUnits units)
7575
{
76-
if (this.units == units) return this;
76+
if (_units == units) return this;
7777

7878
double newValue;
7979
switch (units)
8080
{
8181
case DistanceUnits.Miles:
82-
newValue = value * ConversionConstant;
82+
newValue = _value * ConversionConstant;
8383
break;
8484
case DistanceUnits.Kilometers:
85-
newValue = value / ConversionConstant;
85+
newValue = _value / ConversionConstant;
8686
break;
8787
default:
8888
newValue = 0;
@@ -160,7 +160,7 @@ public override int GetHashCode()
160160
/// <returns>A string representation of this distance.</returns>
161161
public override string ToString()
162162
{
163-
return string.Format("{0} {1}", value, units);
163+
return $"{_value} {_units}";
164164
}
165165

166166
#region Operators
@@ -231,7 +231,7 @@ public override string ToString()
231231
/// <returns><c>true</c> when left is less than right; otherwise <c>false</c>.</returns>
232232
public static bool operator <(Distance left, Distance right)
233233
{
234-
return (left.Value < right.ConvertUnits(left.Units).Value);
234+
return left.Value < right.ConvertUnits(left.Units).Value;
235235
}
236236

237237
/// <summary>
@@ -242,7 +242,7 @@ public override string ToString()
242242
/// <returns><c>true</c> when left is less than or equal to right; otherwise <c>false</c>.</returns>
243243
public static bool operator <=(Distance left, Distance right)
244244
{
245-
return (left.Value <= right.ConvertUnits(left.Units).Value);
245+
return left.Value <= right.ConvertUnits(left.Units).Value;
246246
}
247247

248248
/// <summary>
@@ -253,7 +253,7 @@ public override string ToString()
253253
/// <returns><c>true</c> when left is greater than right; otherwise <c>false</c>.</returns>
254254
public static bool operator >(Distance left, Distance right)
255255
{
256-
return (left.Value > right.ConvertUnits(left.Units).Value);
256+
return left.Value > right.ConvertUnits(left.Units).Value;
257257
}
258258

259259
/// <summary>
@@ -264,7 +264,7 @@ public override string ToString()
264264
/// <returns><c>true</c> when left is greater than or equal to right; otherwise <c>false</c>.</returns>
265265
public static bool operator >=(Distance left, Distance right)
266266
{
267-
return (left.Value >= right.ConvertUnits(left.Units).Value);
267+
return left.Value >= right.ConvertUnits(left.Units).Value;
268268
}
269269

270270
/// <summary>

src/Geocoding.Core/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
22
using Newtonsoft.Json.Converters;
33

44
namespace Geocoding;
@@ -40,7 +40,7 @@ public static void ForEach<T>(this IEnumerable<T> self, Action<T> actor)
4040
}
4141

4242
//Universal ISO DT Converter
43-
static readonly JsonConverter[] JSON_CONVERTERS = new JsonConverter[]
43+
private static readonly JsonConverter[] JSON_CONVERTERS = new JsonConverter[]
4444
{
4545
new IsoDateTimeConverter { DateTimeStyles = System.Globalization.DateTimeStyles.AssumeUniversal },
4646
new StringEnumConverter(),

0 commit comments

Comments
 (0)