summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-16 11:29:40 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-05-16 11:29:40 -0400
commita090b6c21c877e8835f25e1d70d667abf07d1d3c (patch)
treebcd67890749d2f1c7dcdc7e82aba229cbba65d26 /src/SMAPI.Web
parent896f531f4f6fc7f0e8dfcfc0d6433850233ee749 (diff)
downloadSMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.tar.gz
SMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.tar.bz2
SMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.zip
use newer C# features
Diffstat (limited to 'src/SMAPI.Web')
-rw-r--r--src/SMAPI.Web/Controllers/JsonValidatorController.cs32
-rw-r--r--src/SMAPI.Web/Controllers/ModsApiController.cs4
-rw-r--r--src/SMAPI.Web/Framework/Clients/CurseForge/CurseForgeClient.cs3
-rw-r--r--src/SMAPI.Web/Framework/Compression/GzipHelper.cs2
-rw-r--r--src/SMAPI.Web/Startup.cs8
5 files changed, 22 insertions, 27 deletions
diff --git a/src/SMAPI.Web/Controllers/JsonValidatorController.cs b/src/SMAPI.Web/Controllers/JsonValidatorController.cs
index 2ade3e3d..c43fb929 100644
--- a/src/SMAPI.Web/Controllers/JsonValidatorController.cs
+++ b/src/SMAPI.Web/Controllers/JsonValidatorController.cs
@@ -275,21 +275,20 @@ namespace StardewModdingAPI.Web.Controllers
errors = new Dictionary<string, string>(errors, StringComparer.InvariantCultureIgnoreCase);
// match error by type and message
- foreach (var pair in errors)
+ foreach ((string target, string errorMessage) in errors)
{
- if (!pair.Key.Contains(":"))
+ if (!target.Contains(":"))
continue;
- string[] parts = pair.Key.Split(':', 2);
+ string[] parts = target.Split(':', 2);
if (parts[0].Equals(error.ErrorType.ToString(), StringComparison.InvariantCultureIgnoreCase) && Regex.IsMatch(error.Message, parts[1]))
- return pair.Value?.Trim();
+ return errorMessage?.Trim();
}
// match by type
- if (errors.TryGetValue(error.ErrorType.ToString(), out string message))
- return message?.Trim();
-
- return null;
+ return errors.TryGetValue(error.ErrorType.ToString(), out string message)
+ ? message?.Trim()
+ : null;
}
return GetRawOverrideError()
@@ -304,10 +303,10 @@ namespace StardewModdingAPI.Web.Controllers
{
if (schema.ExtensionData != null)
{
- foreach (var pair in schema.ExtensionData)
+ foreach ((string curKey, JToken value) in schema.ExtensionData)
{
- if (pair.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase))
- return pair.Value.ToObject<T>();
+ if (curKey.Equals(key, StringComparison.InvariantCultureIgnoreCase))
+ return value.ToObject<T>();
}
}
@@ -318,14 +317,11 @@ namespace StardewModdingAPI.Web.Controllers
/// <param name="value">The value to format.</param>
private string FormatValue(object value)
{
- switch (value)
+ return value switch
{
- case List<string> list:
- return string.Join(", ", list);
-
- default:
- return value?.ToString() ?? "null";
- }
+ List<string> list => string.Join(", ", list),
+ _ => value?.ToString() ?? "null"
+ };
}
}
}
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs
index 06768f03..e841a075 100644
--- a/src/SMAPI.Web/Controllers/ModsApiController.cs
+++ b/src/SMAPI.Web/Controllers/ModsApiController.cs
@@ -388,9 +388,9 @@ namespace StardewModdingAPI.Web.Controllers
if (map.ContainsKey(parsed.ToString()))
return map[parsed.ToString()];
- foreach (var pair in map)
+ foreach ((string fromRaw, string toRaw) in map)
{
- if (SemanticVersion.TryParse(pair.Key, allowNonStandard, out ISemanticVersion target) && parsed.Equals(target) && SemanticVersion.TryParse(pair.Value, allowNonStandard, out ISemanticVersion newVersion))
+ if (SemanticVersion.TryParse(fromRaw, allowNonStandard, out ISemanticVersion target) && parsed.Equals(target) && SemanticVersion.TryParse(toRaw, allowNonStandard, out ISemanticVersion newVersion))
return newVersion.ToString();
}
}
diff --git a/src/SMAPI.Web/Framework/Clients/CurseForge/CurseForgeClient.cs b/src/SMAPI.Web/Framework/Clients/CurseForge/CurseForgeClient.cs
index 140b854e..a6fd21fd 100644
--- a/src/SMAPI.Web/Framework/Clients/CurseForge/CurseForgeClient.cs
+++ b/src/SMAPI.Web/Framework/Clients/CurseForge/CurseForgeClient.cs
@@ -57,8 +57,7 @@ namespace StardewModdingAPI.Web.Framework.Clients.CurseForge
if (!SemanticVersion.TryParse(raw, out version))
{
- if (invalidVersion == null)
- invalidVersion = raw;
+ invalidVersion ??= raw;
continue;
}
}
diff --git a/src/SMAPI.Web/Framework/Compression/GzipHelper.cs b/src/SMAPI.Web/Framework/Compression/GzipHelper.cs
index cc8f4737..676d660d 100644
--- a/src/SMAPI.Web/Framework/Compression/GzipHelper.cs
+++ b/src/SMAPI.Web/Framework/Compression/GzipHelper.cs
@@ -69,7 +69,7 @@ namespace StardewModdingAPI.Web.Framework.Compression
return rawText;
// decompress
- using (MemoryStream memoryStream = new MemoryStream())
+ using MemoryStream memoryStream = new MemoryStream();
{
// read length prefix
int dataLength = BitConverter.ToInt32(zipBuffer, 0);
diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs
index 07869797..35d22459 100644
--- a/src/SMAPI.Web/Startup.cs
+++ b/src/SMAPI.Web/Startup.cs
@@ -83,7 +83,7 @@ namespace StardewModdingAPI.Web
.AddRazorPages();
// init MongoDB
- services.AddSingleton<MongoDbRunner>(serv => !mongoConfig.IsConfigured()
+ services.AddSingleton<MongoDbRunner>(_ => !mongoConfig.IsConfigured()
? MongoDbRunner.Start()
: throw new InvalidOperationException("The MongoDB connection is configured, so the local development version should not be used.")
);
@@ -265,10 +265,10 @@ namespace StardewModdingAPI.Web
["Modding:Object_data"] = new[] { "^/for-devs/object-data", "^/guides/object-data" },
["Modding:Weather_data"] = new[] { "^/for-devs/weather", "^/guides/weather" }
};
- foreach (KeyValuePair<string, string[]> pair in wikiRedirects)
+ foreach ((string page, string[] patterns) in wikiRedirects)
{
- foreach (string pattern in pair.Value)
- redirects.Add(new RedirectToUrlRule(pattern, "https://stardewvalleywiki.com/" + pair.Key));
+ foreach (string pattern in patterns)
+ redirects.Add(new RedirectToUrlRule(pattern, "https://stardewvalleywiki.com/" + page));
}
return redirects;