-
Notifications
You must be signed in to change notification settings - Fork 56
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
Help text not displaying available Enum string values, when property type is Enum[] #31
Comments
PowerArgs is even more clever than you think (just kidding). You don't need to make your argument an Enum[] to use flags support. The comma separated syntax works even with your standard enum. And you can use Enum.HasFlag(theFlag) to test for flags in your code. I have an example in this test:
|
Interesting! What about Enums where you don't want them to be combinable? What do you think about an amended ArgRevivers.ReviveEnum(Type t, string value, bool ignoreCase): From: if (value.Contains(","))
{
int ret = 0;
var values = value.Split(',').Select(v => v.Trim());
foreach (var enumValue in values)
{
... To: if (value.Contains(","))
{
if (!t.HasAttr<FlagsAttribute>())
{
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
stringBuilder.AppendLine("You cannot specify multiple values for type " + t.Name);
stringBuilder.AppendLine("To allow multiple values, " + t.Name + " must be decorated with the [Flags] attribute.");
stringBuilder.AppendLine("See MSDN for further details:");
stringBuilder.AppendLine(@"http://msdn.microsoft.com/en-us/library/system.flagsattribute(v=vs.110).aspx");
stringBuilder.AppendLine();
stringBuilder.AppendLine("Options are " + string.Join(", ", Enum.GetNames(t)));
throw new ValidationArgException(stringBuilder.ToString());
}
int ret = 0;
var values = value.Split(',').Select(v => v.Trim());
foreach (var enumValue in values)
{
... Or is this sort of check something that would be better placed in a custom Validator/Reviver instead? (The message doesn't necessarily have to be that verbose) |
I'd rather not add more restrictions. I personally have never used that FlagsAttribute, and I can imagine that others might not be either. Like you said, you could build a [NoFlags] validator that explicitly turns off flag support for an enum. That might be a better approach. |
If one of my properties is of type Enum "Category", in the help text displayed, I get a very useful list of the categories available:
![image](https://camo.githubusercontent.com/e4343d925bd40f703ebdd7c16078bba81f817c6afe5981d4d6755c6877600df5/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f353932383230382f313536333338382f35623132366233382d353035662d313165332d383066392d3135613061353038393334352e706e67)
If I decorate this enum with the [Flags] attribute, and specify that multiple categories can be selected, I can change the type of my property to Category[] and PowerArgs is clever enough to parse a comma separated list of categories, and store them against my property.
But
![image](https://camo.githubusercontent.com/ed5ab1b7ee141a3f4f791c403523f1ba00e64e92d08b5fa443bd3488f9aca303/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f353932383230382f313536333431352f64326239633762632d353035662d313165332d393035342d6664386436346238336131632e706e67)
In the help text, it no longer displays the list of Categories the user can choose from:
I don't think this is a Reviver issue, so is there a way to keep that functionality in?
The text was updated successfully, but these errors were encountered: