My goal is to convert a Python function to a function in C# with the same functionality. The important aspect here is that I have information in Python on the input types and output types of the function. This information should be transferred to the function in C#.
Using IronPython I can integrate the Python function to C# with object
as input and output types. Currently I have the following code:
class Program
{
public static void Main(string[] args) {
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
var source = engine.CreateScriptSourceFromString(
"def Add(arg1, arg2):\n" +
" return arg1 +1\n" +
"\n" +
"functionTypes = int" +
"\n" +
"class MyClass(object):\n" +
" def __init__(self, value):\n" +
" self.value = value\n");
source.Execute(scope);
var Add= scope.GetVariable<Func<object, object , object>>("Add");
Console.WriteLine(Add(2,3 ));
But what I would like to have is var Add= scope.GetVariable<Func<functionTypes, functionTypes , functionTypes>>("Add");
where functionTypes represents int.
EDIT: Is there a solution which works for functions with arbitrary inputs. For instance, we want to translate an arbirtary function in python to the same function in c# (including all the types)