OSDN Git Service

using var を使用する
[opentween/open-tween.git] / OpenTween / Thumbnail / Services / FoursquareCheckin.cs
index 9b7caff..d6827d5 100644 (file)
@@ -21,6 +21,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Net.Http;
 using System.Runtime.Serialization.Json;
 using System.Text.RegularExpressions;
@@ -46,9 +47,8 @@ namespace OpenTween.Thumbnail.Services
         public static readonly string ApiBase = "https://api.foursquare.com/v2";
 
         protected HttpClient http
-        {
-            get { return this.localHttpClient ?? Networking.Http; }
-        }
+            => this.localHttpClient ?? Networking.Http;
+
         private readonly HttpClient localHttpClient;
 
         public FoursquareCheckin()
@@ -57,9 +57,7 @@ namespace OpenTween.Thumbnail.Services
         }
 
         public FoursquareCheckin(HttpClient http)
-        {
-            this.localHttpClient = http;
-        }
+            => this.localHttpClient = http;
 
         public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
         {
@@ -114,15 +112,15 @@ namespace OpenTween.Thumbnail.Services
 
                 var apiUrl = new Uri(ApiBase + "/checkins/resolve?" + MyCommon.BuildQueryString(query));
 
-                using (var response = await this.http.GetAsync(apiUrl, token).ConfigureAwait(false))
-                {
-                    response.EnsureSuccessStatusCode();
+                using var response = await this.http.GetAsync(apiUrl, token)
+                    .ConfigureAwait(false);
 
-                    var jsonBytes = await response.Content.ReadAsByteArrayAsync()
-                        .ConfigureAwait(false);
+                response.EnsureSuccessStatusCode();
 
-                    return ParseIntoLocation(jsonBytes);
-                }
+                var jsonBytes = await response.Content.ReadAsByteArrayAsync()
+                    .ConfigureAwait(false);
+
+                return ParseIntoLocation(jsonBytes);
             }
             catch (HttpRequestException)
             {
@@ -160,15 +158,15 @@ namespace OpenTween.Thumbnail.Services
 
                 var apiUrl = new Uri(ApiBase + "/checkins/" + checkinIdGroup.Value + "?" + MyCommon.BuildQueryString(query));
 
-                using (var response = await this.http.GetAsync(apiUrl, token).ConfigureAwait(false))
-                {
-                    response.EnsureSuccessStatusCode();
+                using var response = await this.http.GetAsync(apiUrl, token)
+                    .ConfigureAwait(false);
+
+                response.EnsureSuccessStatusCode();
 
-                    var jsonBytes = await response.Content.ReadAsByteArrayAsync()
-                        .ConfigureAwait(false);
+                var jsonBytes = await response.Content.ReadAsByteArrayAsync()
+                    .ConfigureAwait(false);
 
-                    return ParseIntoLocation(jsonBytes);
-                }
+                return ParseIntoLocation(jsonBytes);
             }
             catch (HttpRequestException)
             {
@@ -178,27 +176,25 @@ namespace OpenTween.Thumbnail.Services
 
         internal static GlobalLocation ParseIntoLocation(byte[] jsonBytes)
         {
-            using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(jsonBytes, XmlDictionaryReaderQuotas.Max))
-            {
-                var xElm = XElement.Load(jsonReader);
+            using var jsonReader = JsonReaderWriterFactory.CreateJsonReader(jsonBytes, XmlDictionaryReaderQuotas.Max);
+            var xElm = XElement.Load(jsonReader);
 
-                var locationElm = xElm.XPathSelectElement("/response/checkin/venue/location");
+            var locationElm = xElm.XPathSelectElement("/response/checkin/venue/location");
 
-                // 座標が得られなかった場合
-                if (locationElm == null)
-                    return null;
+            // 座標が得られなかった場合
+            if (locationElm == null)
+                return null;
 
-                // 月など、地球以外の星の座標である場合
-                var planetElm = locationElm.Element("planet");
-                if (planetElm != null && planetElm.Value != "earth")
-                    return null;
+            // 月など、地球以外の星の座標である場合
+            var planetElm = locationElm.Element("planet");
+            if (planetElm != null && planetElm.Value != "earth")
+                return null;
 
-                return new GlobalLocation
-                {
-                    Latitude = double.Parse(locationElm.Element("lat").Value),
-                    Longitude = double.Parse(locationElm.Element("lng").Value),
-                };
-            }
+            return new GlobalLocation
+            {
+                Latitude = double.Parse(locationElm.Element("lat").Value, CultureInfo.InvariantCulture),
+                Longitude = double.Parse(locationElm.Element("lng").Value, CultureInfo.InvariantCulture),
+            };
         }
     }
 }