Oyen
Oyen

Reputation: 436

enums' Describe attribute in FormDialog fails to be recognized as a valid option

I know I can rely on the system to automatically show SummerLineUp into "Summer Line Up" but I want more control on the displayed texts for my enums.

So I would like to use the Describe attribute for friendlier displays like so:

public enum ProductTypeOptions
{
    [Describe("Summer line up")]
    ProductA = 1,
    [Describe("Fall line up")]
    ProductB = 2,
    [Describe("Winter line up")]
    ProductC = 3,
}

Those show nice and pretty but fails during validation with "Summer line up is not a valid Product Type option".

Is there a different attribute I can use?

Upvotes: 2

Views: 53

Answers (2)

Ashwin Kumar
Ashwin Kumar

Reputation: 1248

A simpler way would be to add the Terms decoration to ProductTypeOptions each item.

So the code would be :

public enum ProductTypeOptions
    {
        [Terms(new string[] { "Summer line up", "Whatever more you want" })]
        [Describe("Summer line up")]
        ProductA = 1,

        [Terms(new string[] { "Fall line up" })]
        [Describe("Fall line up")]
        ProductB = 2,

        [Terms(new string[] { "Winter line up" })]
        [Describe("Winter line up")]
        ProductC = 3,
    };

Now your bot will automatically understand the value of "Summer line up" as ProductA.

Upvotes: 1

Oyen
Oyen

Reputation: 436

I ended up with something acceptable by using the "message" attribute of Describe:

public enum ProductTypeOptions
{
    [Describe("Summer line up", message: "ProductA")]
    ProductA = 1,
    [Describe("Fall line up", message: "ProductB")]
    ProductB = 2,
    [Describe("Winter line up", message: "ProductC")]
    ProductC = 3,
}

When user chooses "Summer line up", the actual message that appears is "ProductA". For what I need, that works fine.

Upvotes: 0

Related Questions