forked from den-run-ai/clrmagic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclrfunction.py
28 lines (24 loc) · 905 Bytes
/
clrfunction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import clr
def create_cs_function(name, code, dependencies = None):
clr.AddReference("MagicIPython")
from MagicIPython import MagicCS
from System import String
from System.Collections.Generic import List
if dependencies is not None and len(dependencies) > 0 :
myarray = List[String]()
for i,d in enumerate(dependencies):
myarray.Add( d )
myarray = myarray.ToArray()
else:
myarray = List[String]().ToArray()
obj = MagicCS.CreateFunction(name, code, myarray)
return lambda *params: run_cs_function(obj, params)
def run_cs_function(func, params):
clr.AddReference("MagicIPython")
from MagicIPython import MagicCS
from System.Collections.Generic import List
from System import Object
par = List[Object]()
for p in params :
par.Add ( p )
return MagicCS.RunFunction(func, par.ToArray())