2011-06-15 99 views
2

考虑这个C#代码:IronPython如何访问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 

有什么我可以做使白色可访问?

回答

2

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

+0

是的,它做到了。有没有办法让公共静态属性可见? public static int MyValue {get {} set {}};似乎并没有出现。 – 2011-06-16 13:44:46

+0

哦,什么是.all?我们可以添加到C#中的东西吗? – 2011-06-16 13:47:26