diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-07 11:29:17 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-07 11:29:17 -0400 |
commit | c5e106801e9137078decfd6b6e3761240b47f94e (patch) | |
tree | 6abc2e197ddce719525f220d00a3dea840d4589f /src/StardewModdingAPI/Framework/Reflection | |
parent | 3b8d1e49f025e56e0442604c2e6956d77d673b0d (diff) | |
download | SMAPI-c5e106801e9137078decfd6b6e3761240b47f94e.tar.gz SMAPI-c5e106801e9137078decfd6b6e3761240b47f94e.tar.bz2 SMAPI-c5e106801e9137078decfd6b6e3761240b47f94e.zip |
split reflection logic out of mod helper (#318)
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> |