/// <summary>Get a private static method.</summary> /// <param name="type">The type which has the method.</param> /// <param name="name">The field name.</param> /// <param name="argumentTypes">The argument types of the method signature to find.</param> /// <param name="required">Whether to throw an exception if the private field is not found.</param> public IPrivateMethod GetPrivateMethod(Type type, string name, Type[] argumentTypes, bool required = true) { // get field from hierarchy PrivateMethod 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 private '{name}' static method with that signature."); } return(method); }
/**** ** Methods by signature ****/ /// <summary>Get a private instance method.</summary> /// <param name="obj">The object which has the method.</param> /// <param name="name">The field name.</param> /// <param name="argumentTypes">The argument types of the method signature to find.</param> /// <param name="required">Whether to throw an exception if the private field is not found.</param> public IPrivateMethod GetPrivateMethod(object obj, string name, Type[] argumentTypes, bool required = true) { // validate parent if (obj == null) { throw new ArgumentNullException(nameof(obj), "Can't get a private instance method from a null object."); } // get method from hierarchy PrivateMethod 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 private '{name}' instance method with that signature."); } return(method); }