[Ironpython-users] How can IronPython access a public static value defined in C#?
Doug Blank
doug.blank at gmail.com
Sat Jun 18 19:33:57 CEST 2011
I asked:
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 with "from ... import *"?
Thanks for any pointers,
-Doug
And Dino (via http://stackoverflow.com/questions/6358222/how-can-ironpython-access-a-public-static-property-defined-in-c)
said:
If you mark the field as readonly then we'll allow importing it via
import * because it'll get added to Graphics.all.
Dino Viehland
I ask follow-up questions:
Yes, that did it. Is there a way to make public static properties visible?
public static int MyValue {
get {}
set {}
};
doesn't seem to appear in "from ... import *".
Oh, and what is .all? Can we add things to that in C#?
-Doug
More information about the Ironpython-users
mailing list