How to pass *varargs? · pythonnet/pythonnet · Discussion #1772
| /// <summary> | |
| /// InvokeMethod Method | |
| /// </summary> | |
| /// <remarks> | |
| /// Invoke the named method of the object with the given arguments. | |
| /// A PythonException is raised if the invocation is unsuccessful. | |
| /// </remarks> | |
| public PyObject InvokeMethod(string name, params PyObject[] args) | |
| { | |
| if (name == null) throw new ArgumentNullException(nameof(name)); | |
| if (args == null) throw new ArgumentNullException(nameof(args)); | |
| if (args.Contains(null)) throw new ArgumentNullException(); | |
| PyObject method = GetAttr(name); | |
| PyObject result = method.Invoke(args); | |
| method.Dispose(); | |
| return result; | |
| } | |
| /// <summary> | |
| /// InvokeMethod Method | |
| /// </summary> | |
| /// <remarks> | |
| /// Invoke the named method of the object with the given arguments. | |
| /// A PythonException is raised if the invocation is unsuccessful. | |
| /// </remarks> | |
| public PyObject InvokeMethod(string name, PyTuple args) | |
| { | |
| if (name == null) throw new ArgumentNullException(nameof(name)); | |
| if (args == null) throw new ArgumentNullException(nameof(args)); | |
| PyObject method = GetAttr(name); | |
| PyObject result = method.Invoke(args); | |
| method.Dispose(); | |
| return result; | |
| } | |
| /// <summary> | |
| /// InvokeMethod Method | |
| /// </summary> | |
| /// <remarks> | |
| /// Invoke the named method of the object with the given arguments. | |
| /// A PythonException is raised if the invocation is unsuccessful. | |
| /// </remarks> | |
| public PyObject InvokeMethod(PyObject name, params PyObject[] args) | |
| { | |
| if (name == null) throw new ArgumentNullException(nameof(name)); | |
| if (args == null) throw new ArgumentNullException(nameof(args)); | |
| if (args.Contains(null)) throw new ArgumentNullException(); | |
| PyObject method = GetAttr(name); | |
| PyObject result = method.Invoke(args); | |
| method.Dispose(); | |
| return result; | |
| } | |
| /// <summary> | |
| /// InvokeMethod Method | |
| /// </summary> | |
| /// <remarks> | |
| /// Invoke the named method of the object with the given arguments. | |
| /// A PythonException is raised if the invocation is unsuccessful. | |
| /// </remarks> | |
| public PyObject InvokeMethod(PyObject name, PyTuple args) | |
| { | |
| if (name == null) throw new ArgumentNullException(nameof(name)); | |
| if (args == null) throw new ArgumentNullException(nameof(args)); | |
| PyObject method = GetAttr(name); | |
| PyObject result = method.Invoke(args); | |
| method.Dispose(); | |
| return result; | |
| } | |
| /// <summary> | |
| /// InvokeMethod Method | |
| /// </summary> | |
| /// <remarks> | |
| /// Invoke the named method of the object with the given arguments | |
| /// and keyword arguments. Keyword args are passed as a PyDict object. | |
| /// A PythonException is raised if the invocation is unsuccessful. | |
| /// </remarks> | |
| public PyObject InvokeMethod(string name, PyObject[] args, PyDict? kw) | |
| { | |
| if (name == null) throw new ArgumentNullException(nameof(name)); | |
| if (args == null) throw new ArgumentNullException(nameof(args)); | |
| if (args.Contains(null)) throw new ArgumentNullException(); | |
| PyObject method = GetAttr(name); | |
| PyObject result = method.Invoke(args, kw); | |
| method.Dispose(); | |
| return result; | |
| } | |
| /// <summary> | |
| /// InvokeMethod Method | |
| /// </summary> | |
| /// <remarks> | |
| /// Invoke the named method of the object with the given arguments | |
| /// and keyword arguments. Keyword args are passed as a PyDict object. | |
| /// A PythonException is raised if the invocation is unsuccessful. | |
| /// </remarks> | |
| public PyObject InvokeMethod(string name, PyTuple args, PyDict? kw) | |
| { | |
| if (name == null) throw new ArgumentNullException(nameof(name)); | |
| if (args == null) throw new ArgumentNullException(nameof(args)); | |
| PyObject method = GetAttr(name); | |
| PyObject result = method.Invoke(args, kw); | |
| method.Dispose(); | |
| return result; | |
| } |