.net IronPython:从脚本中调用不带参数的C#函数

.net IronPython:从脚本中调用不带参数的C#函数,.net,ironpython,.net,Ironpython,我试图在C#应用程序中使用IronPython作为脚本语言。脚本必须使用主应用程序提供的功能(在应用程序或外部库中实现) 虽然这对于只有输入参数的“简单”函数非常有效(就像我发现的任何其他示例中一样),但对于没有参数的函数,这是失败的 示例(C#代码): 然后是IronPython脚本。我希望该值应该设置为3.14,但只能设法得到0.0 import clr import System ret,value = getValue() print("getValue -> %d => %

我试图在C#应用程序中使用IronPython作为脚本语言。脚本必须使用主应用程序提供的功能(在应用程序或外部库中实现)

虽然这对于只有输入参数的“简单”函数非常有效(就像我发现的任何其他示例中一样),但对于没有参数的函数,这是失败的

示例(C#代码):

然后是IronPython脚本。我希望该值应该设置为3.14,但只能设法得到0.0

import clr
import System
ret,value = getValue()
print("getValue -> %d => %s" % (ret, value))  # => output "getValue -> 42 => 0.0

value = clr.Reference[System.Single]()
ret = getValue(value)
print("getValue -> %d => %s" % (ret, value))  # => output "getValue -> 42 => 0.0
我错过什么了吗

注:

  • Out参数也可以与标准库中的函数完美配合使用
  • 大多数时候,当我使用外部库中的函数时,不可能更改方法签名以避免使用out参数
  • 将C#类可见性从默认更改为公共解决了这个问题

    不知道为什么

    import clr
    import System
    ret,value = getValue()
    print("getValue -> %d => %s" % (ret, value))  # => output "getValue -> 42 => 0.0
    
    value = clr.Reference[System.Single]()
    ret = getValue(value)
    print("getValue -> %d => %s" % (ret, value))  # => output "getValue -> 42 => 0.0