Skip to content

Test for Enum.IsDefined in TypeConverter.ToEnum is broken in the face of [Flags] #599

Closed
@ryanmolden

Description

@ryanmolden

The test in CommandLine.Core.TypeConverter.ToEnum which calls Enum.IsDefined is broken if the given enum has the Flags attribute (i.e it ONLY checks if the EXACT given value maps to an enum member, that will never be true for flag combinations of enum members).

This prevents having strongly types enum arguments that are passed on the command line, which is not an uncommon thing (especially in Windows where TONS of interesting data is described via flag style enums).

A workaround is to pass as a raw int/uint/ulong/whatever and just cast inside the program, but thats less ideal than just typing the command line param as what it actually is.

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