Skip to content

Commit 5ac8199

Browse files
committed
Count C# to Python method and type conversion
1 parent 76695b4 commit 5ac8199

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/runtime/converter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ internal static IntPtr ToPython<T>(T value)
156156

157157
internal static IntPtr ToPython(object value, Type type)
158158
{
159+
var outType = Type.GetTypeCode(type) == TypeCode.Object && value != null
160+
? value.GetType()
161+
: type;
162+
163+
if (PyObject.Dict.ContainsKey(outType.Name))
164+
{
165+
PyObject.Dict[outType.Name]++;
166+
}
167+
else
168+
{
169+
PyObject.Dict.Add(outType.Name, 1);
170+
}
159171
if (value is PyObject)
160172
{
161173
IntPtr handle = ((PyObject)value).Handle;

src/runtime/methodbinder.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,24 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
504504
target = co.inst;
505505
}
506506

507+
if (PyObject.Dict.ContainsKey(mi.Name))
508+
{
509+
PyObject.Dict[mi.Name]++;
510+
}
511+
else
512+
{
513+
PyObject.Dict.Add(mi.Name, 1);
514+
}
515+
if (mi.Name.Contains("Log"))
516+
{
517+
;
518+
}
519+
if (mi.Name.Contains("EndOfAlgorithm"))
520+
{
521+
//var sortedDict = from x in PyObject.Dict orderby x.Value descending select $"{x.Key},{x.Value}";
522+
//System.IO.File.WriteAllText("Invoke.txt", string.Join(Environment.NewLine, sortedDict));
523+
}
524+
507525
return new Binding(mi, target, margs, outs);
508526
}
509527
}
@@ -532,7 +550,7 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i
532550

533551
internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo)
534552
{
535-
Binding binding = Bind(inst, args, kw, info, methodinfo);
553+
Binding binding = Bind(inst, args, kw, info, methodinfo);
536554
object result;
537555
IntPtr ts = IntPtr.Zero;
538556

src/runtime/pyobject.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,19 @@ private static IntPtr GetPythonObject(object target)
10271027
return ptr;
10281028
}
10291029

1030+
static public Dictionary<string, int> Dict = new Dictionary<string, int>();
1031+
10301032
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
10311033
{
1034+
if (Dict.ContainsKey(binder.Name))
1035+
{
1036+
Dict[binder.Name]++;
1037+
}
1038+
else
1039+
{
1040+
Dict.Add(binder.Name, 1);
1041+
}
1042+
10321043
if (this.HasAttr(binder.Name) && this.GetAttr(binder.Name).IsCallable())
10331044
{
10341045
PyTuple pyargs = null;

0 commit comments

Comments
 (0)