Skip to content
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

EnumeratedValueArgument w/ Enum #56

Closed
Kritner opened this issue Jan 17, 2018 · 2 comments
Closed

EnumeratedValueArgument w/ Enum #56

Kritner opened this issue Jan 17, 2018 · 2 comments

Comments

@Kritner
Copy link

Kritner commented Jan 17, 2018

At a glance, I'm not seeing a method of using an enum along with EnumeratedValueArgument, specifically when using a attribute style parsing target.

I was hoping for something like:

        public enum MyEnum
        {
            One,
            Two
        }

        [EnumeratedValueArgument(typeof(MyEnum), 'm', "myEnum")]
        public MyEnum ParsedEnum;

or perhaps:

public enum MyEnum
        {
            One,
            Two
        }

        public static Dictionary<MyEnum, string> EnumMapping = new Dictionary<MyEnum, string>()
        {
            { MyEnum.One, "do something with one" },
            { MyEnum.Two, "do something with two" },
        };

        [EnumeratedValueArgument(typeof(string), 'm', "myEnum", AllowedValues = string.Join(";", EnumMapping.Keys)]
        public string ParsedEnum;

but that gives:

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

any ideas on this sort of functionality?

@j-maly
Copy link
Owner

j-maly commented Jan 17, 2018

EnumeratedValueArgument is not the best here. It is meant for cases where you have a known set of primitive values you want to allow. E.g. 1,2,3,4,5,6

You can use plain ValueArgument:

ValueArgument<MyEnum> //(in code) 

or

[ValueArgument(typeof(MyEnum),...)] //(in attributes)

it should work fine for you

@Kritner
Copy link
Author

Kritner commented Jan 17, 2018

Darn, guess no method for grabbing the list of valid values from the enum using that attribute either eh?

@Kritner Kritner closed this as completed Jan 18, 2018
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

No branches or pull requests

2 participants