diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-05-16 11:29:40 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-05-16 11:29:40 -0400 |
commit | a090b6c21c877e8835f25e1d70d667abf07d1d3c (patch) | |
tree | bcd67890749d2f1c7dcdc7e82aba229cbba65d26 /src/SMAPI.Web/Controllers/JsonValidatorController.cs | |
parent | 896f531f4f6fc7f0e8dfcfc0d6433850233ee749 (diff) | |
download | SMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.tar.gz SMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.tar.bz2 SMAPI-a090b6c21c877e8835f25e1d70d667abf07d1d3c.zip |
use newer C# features
Diffstat (limited to 'src/SMAPI.Web/Controllers/JsonValidatorController.cs')
-rw-r--r-- | src/SMAPI.Web/Controllers/JsonValidatorController.cs | 32 |
1 files changed, 14 insertions, 18 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" + }; } } } |