From 5b24fff4771dd11c627ae20c827599fe37fa89ad Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 13 Apr 2022 20:41:34 -0400 Subject: remove unused code (#837) --- src/SMAPI/Framework/Reflection/Reflector.cs | 57 ----------------------------- 1 file changed, 57 deletions(-) (limited to 'src/SMAPI/Framework/Reflection') diff --git a/src/SMAPI/Framework/Reflection/Reflector.cs b/src/SMAPI/Framework/Reflection/Reflector.cs index d5938c3f..c6fc2c79 100644 --- a/src/SMAPI/Framework/Reflection/Reflector.cs +++ b/src/SMAPI/Framework/Reflection/Reflector.cs @@ -1,7 +1,6 @@ #nullable disable using System; -using System.Linq; using System.Reflection; using System.Runtime.Caching; @@ -128,41 +127,6 @@ namespace StardewModdingAPI.Framework.Reflection return method; } - /**** - ** Methods by signature - ****/ - /// Get a instance method. - /// The object which has the method. - /// The field name. - /// The argument types of the method signature to find. - /// Whether to throw an exception if the field is not found. - public IReflectedMethod GetMethod(object obj, string name, Type[] argumentTypes, bool required = true) - { - // validate parent - if (obj == null) - throw new ArgumentNullException(nameof(obj), "Can't get a instance method from a null object."); - - // get method from hierarchy - ReflectedMethod method = this.GetMethodFromHierarchy(obj.GetType(), obj, name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, argumentTypes); - if (required && method == null) - throw new InvalidOperationException($"The {obj.GetType().FullName} object doesn't have a '{name}' instance method with that signature."); - return method; - } - - /// Get a static method. - /// The type which has the method. - /// The field name. - /// The argument types of the method signature to find. - /// Whether to throw an exception if the field is not found. - public IReflectedMethod GetMethod(Type type, string name, Type[] argumentTypes, bool required = true) - { - // get field from hierarchy - ReflectedMethod method = this.GetMethodFromHierarchy(type, null, name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, argumentTypes); - if (required && method == null) - throw new InvalidOperationException($"The {type.FullName} object doesn't have a '{name}' static method with that signature."); - return method; - } - /********* ** Private methods @@ -232,27 +196,6 @@ namespace StardewModdingAPI.Framework.Reflection : null; } - /// Get a method from the type hierarchy. - /// The type which has the method. - /// The object which has the method. - /// The method name. - /// The reflection binding which flags which indicates what type of method to find. - /// The argument types of the method signature to find. - private ReflectedMethod GetMethodFromHierarchy(Type type, object obj, string name, BindingFlags bindingFlags, Type[] argumentTypes) - { - bool isStatic = bindingFlags.HasFlag(BindingFlags.Static); - MethodInfo method = this.GetCached($"method::{isStatic}::{type.FullName}::{name}({string.Join(",", argumentTypes.Select(p => p.FullName))})", () => - { - MethodInfo methodInfo = null; - for (; type != null && methodInfo == null; type = type.BaseType) - methodInfo = type.GetMethod(name, bindingFlags, null, argumentTypes, null); - return methodInfo; - }); - return method != null - ? new ReflectedMethod(type, obj, method, isStatic) - : null; - } - /// Get a method or field through the cache. /// The expected type. /// The cache key. -- cgit