diff --git a/IPA.Loader/Utilities/ReflectionUtil.cs b/IPA.Loader/Utilities/ReflectionUtil.cs index b47f6c1c..593669c3 100644 --- a/IPA.Loader/Utilities/ReflectionUtil.cs +++ b/IPA.Loader/Utilities/ReflectionUtil.cs @@ -29,15 +29,15 @@ namespace IPA.Utilities /// /// Gets the value of a field. /// - /// the type of the field (result casted) - /// the type to get the field from + /// the type to get the field from + /// the type of the field (result casted) /// the object instance to pull from /// the name of the field to read /// the value of the field - /// if does not exist on + /// if does not exist on /// - public static T GetField(this U obj, string fieldName) - => FieldAccessor.Get(ref obj, fieldName); + public static U GetField(this T obj, string fieldName) + => FieldAccessor.Get(ref obj, fieldName); /// /// Sets a property on the target object, as gotten from . @@ -62,7 +62,7 @@ namespace IPA.Utilities /// the value of the property /// if does not exist on /// - public static U GetProperty(this T obj, string propertyName) + public static U GetProperty(this T obj, string propertyName) => PropertyAccessor.Get(ref obj, propertyName); /// @@ -73,28 +73,14 @@ namespace IPA.Utilities /// the method's name /// the method arguments /// the return value - /// if does not exist on - public static object InvokeMethod(this T obj, string methodName, params object[] args) + /// if does not exist on + public static U InvokeMethod(this T obj, string methodName, params object[] args) { var dynMethod = typeof(T).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); - if (dynMethod == null) throw new ArgumentException($"Method {methodName} does not exist", nameof(methodName)); - return dynMethod?.Invoke(obj, args); + if (dynMethod == null) throw new MissingMethodException($"Method {methodName} does not exist", nameof(methodName)); + return (U)dynMethod?.Invoke(obj, args); } - /// - /// Invokes a method from on an object. - /// - /// the return type - /// the type to search for the method on - /// the object instance - /// the method name to call - /// the method's arguments - /// the return value - /// if does not exist on - /// - public static T InvokeMethod(this U obj, string methodName, params object[] methodArgs) - => (T)InvokeMethod(obj, methodName, methodArgs); - /// /// Copies a component to a component of on the destination . ///