Skip to content

Sypport typeof(T) or clr.GetClrType #432

Closed
@vivainio

Description

@vivainio

In order to do reflection, you need to acquire the Type instance for imported class.

In C#, this is done by

Type t = typeof(MyClass)

In IronPython, this is done by

t = clr.GetClrType(MyClass)

Python.net seems to be missing this functionality.

I currently have this horrible hack, and I'm unsure how far it will work:

def get_clr_type(typ):
    """ simulate typeof(T) or GetClrType from IronPython.

    Horrible hack, redo
    """
    name = typ.__module__ + "." + typ.__name__
    return Type.GetType(name)

For reference, code using this resides in: https://github.com/vivainio/pynetext/blob/master/pynetext.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions