【问题标题】:How can IronPython access a public static property defined in C#?IronPython 如何访问 C# 中定义的公共静态属性?
【发布时间】:2011-06-15 13:14:59
【问题描述】:

考虑一下这个 C# 代码:

public static class Graphics {
  public static Color white = new Color(255, 255, 255);
}

我可以从 IronPython 编译和导入它:

>>> import clr
>>> clr.AddReference("Graphics")
>>> import Graphics
>>> Graphics.white
<Color 255,255,255>

但我不能:

>>> import clr
>>> clr.AddReference("Graphics")
>>> from Graphics import *
>>> white
Traceback (most recent call last):
  File "/home/dblank/Calico/src/engine.py", line 159, in execute
    source.Execute(self.manager.scope)
  File "<string>", line 1, in <module>
<type 'exceptions.NameError'>: name 'white' is not defined

我可以做些什么来让白色变得容易接近吗?

【问题讨论】:

    标签: c# static import ironpython public


    【解决方案1】:

    如果您将该字段标记为只读,那么我们将允许通过 import * 将其导入,因为它将被添加到 Graphics。全部

    【讨论】:

    • 是的,做到了。有没有办法让公共静态属性可见?公共静态 int MyValue { 获取 {} 设置 {} };似乎没有出现。
    • 哦,.all 是什么?我们可以在 C# 中添加一些东西吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    • 2012-08-13
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多