How to get CLR type of Python class?
See original GitHub issuePrerequisites
- Are you running the latest version?
- Are you reporting to the correct repository?
- Did you perform a cursory search?
Description
So, we have as task getting CLR type of strongly typed class in IronPython, if possible, without invoking constructor. Example:
class Vehicle(Component):
__metaclass__ = clrtype.ClrClass
_Test = SpecialProperty[int]()
@property
@clrtype.accepts()
@clrtype.returns(SpecialProperty[int])
def Test(self):
return self._Test
def __init__(this, *args):
return Component.__new__(type(this), *args)
Possible ways at now:
- Create object of this type and invoke
GetType()
from it. Example:
CompiledCode compiled = source.Compile();
compiled.Execute();
var pythonType = compiled.DefaultScope.GetVariable("Vehicle");
var obj = ops.CreateInstance(type, new object[] { Guid.NewGuid() });
var clrType = obj.GetType();
- Get base class type by accessing constructor.
Example:
var clrType = pythonType.__new__.Overloads.Targets[0].DeclaringType;
- Playing with “internal” methods of IronPython, but it’s hard.
Affiliated problems and possible fixes
pythonType.GetType()
throwsSystem.MissingMemberException
, but should return something liketypeof(IronPython.NewTypes.IronPython.Runtime.Types.PythonType_2$2)
ortypeof(IronPython.Runtime.Types.PythonType)
.pythonType.__new__.Overloads.Function.DeclaringType
returnSystem.Object
, but by logic, should return proper containing type.IronPython.Runtime.Types.PythonType
should have reference to CLR type, if available.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python clr.GetClrType() Examples - ProgramCreek.com
You can vote up the ones you like or vote down the ones you don't like, and go to the original project or...
Read more >Type of an IronPython object - Stack Overflow
IronPython use the reflexion to handle .NET types. The .GetType() method calls the type from CLR. Its the same as calling clr.
Read more >[Python.NET] Subclassing CLR types
Hi, subclassing CLR types does work as long as you hold a ... retrieve this object later through a method of the CLR...
Read more >__clrtype__ Metaclasses: Customizing the Type Name - DevHawk
class ClrTypeMetaclass (type): def __clrtype__(cls): baseType ... Type that IronPython would have used as the underlying CLR type for the Python class if...
Read more >CLR Inside Out: IronPython - Microsoft Learn
But just having dynamic types does not make a language dynamic. ... compare the amount of code that goes into simple C# or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not sure I follow what the issue is.
pythonType
is a CLR type.@DjArt Looks like I was incorrect,
pythonType is PythonType
is correct. But thePythonType
can be cast toType
.