开发者

How can IronPython access a public static property defined in C#?

Consider this C# code:

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

I can compile and import this from IronPython:

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

But I can't:

>>> 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 &l开发者_JAVA百科t;module>
<type 'exceptions.NameError'>: name 'white' is not defined

Is there something I can do to make white accessible?


If you mark the field as readonly then we'll allow importing it via import * because it'll get added to Graphics.all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜