私は追加の「無料」ツールとして Iron Python を使用して、通信をカスタム ハードウェアにラップする API をテストし、非開発チームが Python 経由でハードウェアを操作できるようにしています。
void func(params object[] args)
ただし、.NETを Python にマップする方法がわかりませんdef (*args)
。
説明するコードを次に示します。
Console.WriteLine と Debug.WriteLine のシグネチャに従って、ロギング コールバックを挿入してメッセージをフォーマットおよび処理できるタイプがあります。
public class Engine
{
Action<string, object[]> _logger;
public void Run()
{
Log("Hello '{0}'", "world");
}
public void SetLog(Action<string, object[]> logger)
{
_logger = logger;
}
void Log(string msg, params object[] args)
{
_logger(msg, args);
}
}
私のIronPythonコードで
import clr
from System import *
from System.IO import Path
clr.AddReferenceToFileAndPath(Path.GetFullPath(r"MyAssembly.dll"))
from MyNamespace import *
def logger(msg, *args):
print( String.Format(msg, args))
print( String.Format(msg, list(args)))
print( String.Format(msg, [args]))
a=[]
for i in args:
a.append(i)
print( String.Format(msg, a) )
e = Engine()
e.SetLog(logger)
e.Run()
出力
Hello '('world',)'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'
をお願いします。
Hello 'world'