Skip to content

Get Value Of An Enum #1585

@saroad2

Description

@saroad2

Environment

  • Pythonnet version: latest
  • Python version: 3.9.4
  • Operating System: Windows
  • .NET Runtime:

Details

  • Describe what you were trying to get done.

I would like to have the ability to extract the value of a .Net Enum via python. One can do that using MyEnum.value__, however it seems logical that you should do it using int(MyEnum).

import clr

clr.AddReference("System.Windows.Forms")

import System.Windows.Forms as WinForms

enum_value = WinForms.Keys.Control
print(f"{enum_value=}")
print(f"{enum_value.value__=}")

That prints:

enum_value=<System.Windows.Forms.Keys object at 0x000001C053E07580>
enum_value.value__=131072
  • If there was a crash, please include the traceback here.

No crash.

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions