Python .net framework reference argument Double[]&

≡放荡痞女 提交于 2019-12-04 10:55:31

You can call this method by providing a list (or tuple) of floats as a second parameter.

MyClass.ExternalFunction(myName, [0.0]);

There will be a conversion between 2 different data structures in 2 virtual machines. Python.Net will convert python's list of floats to an array of doubles in .Net environment and pass it by reference to your function. Changes made to second parameter will not be propagated back to python.

By using reflection you can get more control over parameters marshaling.

import clr
clr.AddReference("MyDll")
import System
import MyLib

myClassType = System.Type.GetType("MyLib.MyClass, MyDll") 
method = myClassType.GetMethod("ExternalFunction")
numbersArray = System.Array[System.Double]([1.0, 2.0, 3.0])
parameters = System.Array[System.Object](["Benjamin",numbersArray])
method.Invoke(None,parameters)


numbersArray = parameters[1] # an updated Arg2 can be retrieved from parameters array
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!