diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-08 12:54:06 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-08 12:54:06 -0400 |
commit | 1edd98aef027faa768f56cf0b3591e64e20ba096 (patch) | |
tree | aec210e2b44c9654f29572dd084206a4598896e1 /src/StardewModdingAPI/Framework/Reflection | |
parent | 36930ffd7d363d6afd7f8cac4918c7d1c1c3e339 (diff) | |
parent | 8743c4115aa142113d791f2d2cd9ba811dcada2c (diff) | |
download | SMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.tar.gz SMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.tar.bz2 SMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Framework/Reflection')
-rw-r--r-- | src/StardewModdingAPI/Framework/Reflection/Reflector.cs (renamed from src/StardewModdingAPI/Framework/Reflection/ReflectionHelper.cs) | 44 |
1 files changed, 2 insertions, 42 deletions
diff --git a/src/StardewModdingAPI/Framework/Reflection/ReflectionHelper.cs b/src/StardewModdingAPI/Framework/Reflection/Reflector.cs index 7a5789dc..5c2d90fa 100644 --- a/src/StardewModdingAPI/Framework/Reflection/ReflectionHelper.cs +++ b/src/StardewModdingAPI/Framework/Reflection/Reflector.cs @@ -7,13 +7,13 @@ namespace StardewModdingAPI.Framework.Reflection { /// <summary>Provides helper methods for accessing private game code.</summary> /// <remarks>This implementation searches up the type hierarchy, and caches the reflected fields and methods with a sliding expiry (to optimise performance without unnecessary memory usage).</remarks> - internal class ReflectionHelper : IReflectionHelper + internal class Reflector { /********* ** Properties *********/ /// <summary>The cached fields and methods found via reflection.</summary> - private readonly MemoryCache Cache = new MemoryCache(typeof(ReflectionHelper).FullName); + private readonly MemoryCache Cache = new MemoryCache(typeof(Reflector).FullName); /// <summary>The sliding cache expiration time.</summary> private readonly TimeSpan SlidingCacheExpiry = TimeSpan.FromMinutes(5); @@ -94,46 +94,6 @@ namespace StardewModdingAPI.Framework.Reflection } /**** - ** Field values - ** (shorthand since this is the most common case) - ****/ - /// <summary>Get the value of a private instance field.</summary> - /// <typeparam name="TValue">The field type.</typeparam> - /// <param name="obj">The object which has the field.</param> - /// <param name="name">The field name.</param> - /// <param name="required">Whether to throw an exception if the private field is not found.</param> - /// <returns>Returns the field value, or the default value for <typeparamref name="TValue"/> if the field wasn't found and <paramref name="required"/> is false.</returns> - /// <remarks> - /// This is a shortcut for <see cref="GetPrivateField{TValue}(object,string,bool)"/> followed by <see cref="IPrivateField{TValue}.GetValue"/>. - /// When <paramref name="required" /> is false, this will return the default value if reflection fails. If you need to check whether the field exists, use <see cref="GetPrivateField{TValue}(object,string,bool)" /> instead. - /// </remarks> - public TValue GetPrivateValue<TValue>(object obj, string name, bool required = true) - { - IPrivateField<TValue> field = this.GetPrivateField<TValue>(obj, name, required); - return field != null - ? field.GetValue() - : default(TValue); - } - - /// <summary>Get the value of a private static field.</summary> - /// <typeparam name="TValue">The field type.</typeparam> - /// <param name="type">The type which has the field.</param> - /// <param name="name">The field name.</param> - /// <param name="required">Whether to throw an exception if the private field is not found.</param> - /// <returns>Returns the field value, or the default value for <typeparamref name="TValue"/> if the field wasn't found and <paramref name="required"/> is false.</returns> - /// <remarks> - /// This is a shortcut for <see cref="GetPrivateField{TValue}(Type,string,bool)"/> followed by <see cref="IPrivateField{TValue}.GetValue"/>. - /// When <paramref name="required" /> is false, this will return the default value if reflection fails. If you need to check whether the field exists, use <see cref="GetPrivateField{TValue}(Type,string,bool)" /> instead. - /// </remarks> - public TValue GetPrivateValue<TValue>(Type type, string name, bool required = true) - { - IPrivateField<TValue> field = this.GetPrivateField<TValue>(type, name, required); - return field != null - ? field.GetValue() - : default(TValue); - } - - /**** ** Methods ****/ /// <summary>Get a private instance method.</summary> |