Skip to content

Reworked Enum marshaling #1392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

lostmsu
Copy link
Member

@lostmsu lostmsu commented Feb 20, 2021

What does this implement/fix? Explain your changes.

  • enums are no longer converted to and from PyLong automatically .NET enums should not be automatically converted to Python int and back #1220
  • one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10)
  • in the above, if MyEnum does not have [Flags] and does not have member with value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion
  • legacy behavior has been moved to a codec: EnumPyLongCodec; enums can now be encoded by codecs
  • added EnumOps class, that implements bitwise operations on [Flags] enums.

Does this close any currently open issues?

#1220

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • Updated the CHANGELOG

@lostmsu lostmsu force-pushed the PR/Disable-Enum-Implicit-Conv-To-Int branch from c00ae2b to 429cc3b Compare February 20, 2021 22:42
@lostmsu lostmsu marked this pull request as draft February 20, 2021 22:47
@lostmsu lostmsu force-pushed the PR/Disable-Enum-Implicit-Conv-To-Int branch from 429cc3b to 9bff356 Compare February 21, 2021 00:59
@lostmsu lostmsu marked this pull request as ready for review February 21, 2021 01:04
@lostmsu lostmsu force-pushed the PR/Disable-Enum-Implicit-Conv-To-Int branch 2 times, most recently from 48655d8 to f77b131 Compare February 21, 2021 06:15
- enums are no longer converted to and from PyLong automatically pythonnet#1220
- one can construct an instance of MyEnum from Python using MyEnum(numeric_val), e.g. MyEnum(10)
- in the above, if MyEnum does not have [Flags] and does not have value 10 defined, to create MyEnum with value 10 one must call MyEnum(10, True). Here True is an unnamed parameter, that allows unchecked conversion
- legacy behavior has been moved to a codec (EnumPyLongCodec); enums can now be encoded by codecs
- flags enums support bitwise ops via EnumOps class
@lostmsu lostmsu force-pushed the PR/Disable-Enum-Implicit-Conv-To-Int branch from f77b131 to 5c41499 Compare March 30, 2021 23:44
@lostmsu lostmsu merged commit 6379221 into pythonnet:master Mar 30, 2021
@lostmsu lostmsu deleted the PR/Disable-Enum-Implicit-Conv-To-Int branch March 30, 2021 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant