18 using System.Collections.Generic;
20 using System.Reflection;
37 var notInterface = !typeof(TInterface).IsInterface;
38 var missingMembers =
new List<string>();
39 var members = typeof(TInterface).GetMembers(BindingFlags.Public | BindingFlags.Instance);
42 foreach (var member
in members)
44 var method = member as MethodInfo;
45 if ((method ==
null || !method.IsSpecialName) &&
46 !model.HasAttr(member.Name) && !model.HasAttr(member.Name.ToSnakeCase()))
50 if (method !=
null && !method.IsAbstract && (method.IsFinal || !method.IsVirtual || method.DeclaringType != typeof(TInterface)))
54 else if (member is ConstructorInfo)
58 else if (member.Name is
"ToString")
63 missingMembers.Add(member.Name);
67 if (missingMembers.Any())
69 throw new NotImplementedException(
84 public static T
InvokeMethod<T>(
this PyObject model,
string methodName, params
object[] args)
86 using var _ = Py.GIL();
87 return InvokeMethodImpl(model, methodName, args).GetAndDispose<T>();
96 public static void InvokeMethod(
this PyObject model,
string methodName, params
object[] args)
98 InvokeMethodImpl(model, methodName, args);
107 public static T
Invoke<T>(
this PyObject method, params
object[] args)
109 using var _ = Py.GIL();
110 return InvokeMethodImpl(method, args).GetAndDispose<T>();
118 public static PyObject
Invoke(
this PyObject method, params
object[] args)
120 return InvokeMethodImpl(method, args);
123 private static PyObject InvokeMethodImpl(PyObject model,
string methodName, params
object[] args)
125 using var _ = Py.GIL();
126 PyObject method = model.GetMethod(methodName);
127 return InvokeMethodImpl(method, args);
130 private static PyObject InvokeMethodImpl(PyObject method, params
object[] args)
132 using var _ = Py.GIL();
133 return method.Invoke(args.Select(arg => arg.ToPython()).ToArray());