Try passing Actionor Funcinstead of a simple function:
IronPython ( , Python.NET documentation ,
, Action Func, , .
python:
import clr
from types import *
from System import Action
clr.AddReferenceToFileAndPath(r"YourPath\TestLib.dll")
import TestLib
print("Hello")
mc = TestLib.MC()
print(mc.method1(10))
def f(fakeparam):
print "exec f"
mc.method2(Action[int](f))
:
Hello
Executing method1
42.0
Executing method2
exec f
Done executing method2
#:
using System;
namespace TestLib
{
public class MC
{
public double method1(int n)
{
Console.WriteLine("Executing method1");
return 42.0;
}
public double method2(Delegate f)
{
Console.WriteLine("Executing method2");
object[] paramToPass = new object[1];
paramToPass[0] = new int();
f.DynamicInvoke(paramToPass);
Console.WriteLine("Done executing method2");
return 24.0;
}
}
}
Python.net Generics, Python.NET ,
:
a () ( , ). []. generic def, (), TypeError.