IronPython 如何访问 C# 中定义的公共静态属性?
考虑这个 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
我可以做些什么来使白色变得可访问吗?
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 <module>
<type 'exceptions.NameError'>: name 'white' is not defined
Is there something I can do to make white accessible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将该字段标记为只读,那么我们将允许通过 import * 导入它,因为它将被添加到 Graphics.all 中。
If you mark the field as readonly then we'll allow importing it via import * because it'll get added to Graphics.all.