How the clr module works with .NET imports
I'm curious about how the clr module and the subsequent imports work. I'm asking for a hand in understanding that since that's some pretty dense code for me to understand by myself. I'm doing this because I'm trying to have the same functions in my own pure .NET, async-await Python interpreter project. I have a fairly simple example I am using as a test that I got originally from IronPython--that also works with Python.NET:
import clr clr.AddReference("System") <System.Reflection.RuntimeAssembly object at 0x0000022C20DA2438> from System import Environment Environment <class 'System.Environment'>
Two questions: 1. Generally how does Python.NET track these references? I assumed there'd be a module loader for .NET DLLs but saw nothing in sys.meta_path. In my own project, I've been polluting the local context with a a __clr__ dunder. 2. How does Python.NET get Environment out of the System reference? Is it a misnomer? Environment's in mscorlib but the System namespace. I'm treating AddReference("System") as adding the System assembly, but I suppose it's more applicable to say it's adding the System namespace. I don't know how to represent that in .NET parlance. I found this, which seems rather tedious! https://stackoverflow.com/questions/79693/getting-all-types-in-a-namespace-v... Presumably that would mean going through all references and finding matching namespaces.
participants (1)
-
adam.preble@gmail.com