diff options
Diffstat (limited to 'src/SMAPI/Framework/InternalExtensions.cs')
-rw-r--r-- | src/SMAPI/Framework/InternalExtensions.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/InternalExtensions.cs b/src/SMAPI/Framework/InternalExtensions.cs index 71489627..ce67ae18 100644 --- a/src/SMAPI/Framework/InternalExtensions.cs +++ b/src/SMAPI/Framework/InternalExtensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json.Linq; using StardewModdingAPI.Framework.Reflection; using StardewValley; @@ -148,5 +149,20 @@ namespace StardewModdingAPI.Framework // get result return reflection.GetField<bool>(Game1.spriteBatch, fieldName).GetValue(); } + + /**** + ** Json.NET + ****/ + /// <summary>Get a JSON field value from a case-insensitive field name. This will check for an exact match first, then search without case sensitivity.</summary> + /// <typeparam name="T">The value type.</typeparam> + /// <param name="obj">The JSON object to search.</param> + /// <param name="fieldName">The field name.</param> + public static T ValueIgnoreCase<T>(this JObject obj, string fieldName) + { + JToken token = obj.GetValue(fieldName, StringComparison.InvariantCultureIgnoreCase); + return token != null + ? token.Value<T>() + : default(T); + } } } |