Skip to content

Commit 49e6b0d

Browse files
committed
Tidy remaining sample and parser review feedback
Root cause: a few low-risk review comments remained open after the provider cleanup even though the behavior-preserving fixes were straightforward. Alphabetize the sample provider switch and make the Core/Bing filtering logic explicit so the outstanding review feedback matches the current implementation.
1 parent 431a9f8 commit 49e6b0d

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

samples/Example.Web/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ static bool TryCreateGeocoder(string provider, ProviderOptions options, out IGeo
130130
{
131131
switch (provider.Trim().ToLowerInvariant())
132132
{
133-
case "google":
134-
geocoder = String.IsNullOrWhiteSpace(options.Google.ApiKey)
135-
? new GoogleGeocoder()
136-
: new GoogleGeocoder(options.Google.ApiKey);
137-
error = null;
138-
return true;
139-
140133
case "azure":
141134
if (String.IsNullOrWhiteSpace(options.Azure.ApiKey))
142135
{
@@ -161,6 +154,13 @@ static bool TryCreateGeocoder(string provider, ProviderOptions options, out IGeo
161154
error = null;
162155
return true;
163156

157+
case "google":
158+
geocoder = String.IsNullOrWhiteSpace(options.Google.ApiKey)
159+
? new GoogleGeocoder()
160+
: new GoogleGeocoder(options.Google.ApiKey);
161+
error = null;
162+
return true;
163+
164164
case "here":
165165
geocoder = default!;
166166
if (String.IsNullOrWhiteSpace(options.Here.ApiKey))

src/Geocoding.Core/Serialization/TolerantStringEnumConverter.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq;
12
using System.Text.Json;
23
using System.Text.Json.Serialization;
34

@@ -58,11 +59,12 @@ public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOpt
5859

5960
private static TEnum GetFallbackValue()
6061
{
61-
foreach (string name in Enum.GetNames(EnumType))
62-
{
63-
if (String.Equals(name, "Unknown", StringComparison.OrdinalIgnoreCase))
64-
return (TEnum)Enum.Parse(EnumType, name);
65-
}
62+
string? unknownName = Enum.GetNames(EnumType)
63+
.Where(name => String.Equals(name, "Unknown", StringComparison.OrdinalIgnoreCase))
64+
.FirstOrDefault();
65+
66+
if (unknownName is not null)
67+
return (TEnum)Enum.Parse(EnumType, unknownName);
6668

6769
return default;
6870
}

src/Geocoding.Microsoft/BingMapsGeocoder.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Globalization;
22
using System.Net;
33
using System.Net.Http;
4+
using System.Linq;
45
using System.Text;
56
using System.Text.Json;
67

@@ -252,20 +253,17 @@ protected virtual IEnumerable<BingAddress> ParseResponse(Json.Response response)
252253
if (locations.IsNullOrEmpty())
253254
continue;
254255

255-
foreach (var location in locations)
256+
foreach (var location in locations.Where(location => location?.Point?.Coordinates is { Length: >= 2 }
257+
&& location.Address is not null
258+
&& !String.IsNullOrWhiteSpace(location.Address.FormattedAddress)))
256259
{
257-
if (location.Point is null || location.Address is null)
258-
continue;
259-
260-
var coordinates = location.Point.Coordinates;
261-
if (coordinates is null || coordinates.Length < 2 || String.IsNullOrWhiteSpace(location.Address.FormattedAddress))
262-
continue;
260+
var coordinates = location!.Point!.Coordinates!;
263261

264262
if (!Enum.TryParse(location.EntityType, out EntityType entityType))
265263
entityType = EntityType.Unknown;
266264

267265
list.Add(new BingAddress(
268-
location.Address.FormattedAddress!,
266+
location.Address!.FormattedAddress!,
269267
new Location(coordinates[0], coordinates[1]),
270268
location.Address.AddressLine,
271269
location.Address.AdminDistrict,

0 commit comments

Comments
 (0)