IronPython如何访问C#中定义的公共静态属性?

时间:2011-06-15 13:15:00

标签: c# static import ironpython public

考虑这个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

我能做些什么才能让白色变得容易接触?

1 个答案:

答案 0 :(得分:2)

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