Skip to content

ExistsIn validation fails with non-int backed Enums #139

@fsateler

Description

@fsateler

The currently released version (2.1.0), currently casts enums to int when fetching possible values, to be able to compare the string representation.

This fails with short or long backed enums with an InvalidCastException.

This could be fixed by using Convert.ToInt32 instead. But I wonder if this is the right approach at all? I would have expected that the ExistsIn attribute refers to a property that has the same type as the target property. If I'm interpreting the code correctly, the following code would fail:

[ExistsIn("Values", "Key", "Value")]
public MyEnum Property {get;set;}
public Dictionary<MyEnum,string> Values = ...;

Because only the values fetched from Values are converted to int, but the Property value is not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions