Content-Length: 370725 | pFad | https://github.com/pythonnet/pythonnet/issues/432

68 Sypport typeof(T) or clr.GetClrType · Issue #432 · pythonnet/pythonnet · GitHub
Skip to content

Sypport typeof(T) or clr.GetClrType #432

@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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/pythonnet/pythonnet/issues/432

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy