使用术语属性来控制每个项目栏的选择

我正在试验 Bot Framework 教程附带的 Sandwich Order 示例。在该示例代码中,有一个SandwichOrder包含用于存储浇头的列表属性的类。


public enum ToppingOptions

{

    [Terms("except", "but", "not", "no", "all", "everything")]

    Everything = 1,


    Avocado, BananaPeppers, Cucumbers, GreenBellPeppers, Jalapenos,

    Lettuce, Olives, Pickles, RedOnion, Spinach, Tomatoes

}


[Serializable]

public class SandwichOrder

{

    [Prompt("Which {&} would you like? {||}")]

    [Describe("toppings")]

    public List<ToppingOptions> Toppings;


    public static IForm<SandwichOrder> BuildForm()

    {

        return new FormBuilder<SandwichOrder>()

            .Message("Welcome to the simple sandwich order bot!")

            .Build();

    }

};

我正在试验该Terms属性,如此处所述


FormFlow 的高级功能

当我在模拟器中运行机器人时,选择浇头的问题按预期出现......

http://img4.mukewang.com/60e962cd000133bf03110367.jpg

我像这样输入我的选择......

http://img.mukewang.com/60e962d70001117b01970063.jpg

结果不是我所期望的。机器人总结了我的选择是这样的......

http://img.mukewang.com/60e962e30001c2e602780105.jpg

根据教程,结果应该是......

http://img.mukewang.com/60e962f20001b1f910560110.jpg

我不清楚我在这里哪里出错了。有人可以帮我吗?


DIEA
浏览 181回答 1
1回答

四季花海

事实上,我认为您错过了本教程的一部分。您需要在构建器中添加代码来处理“一切”和“但是”这个词。下面的代码显示了如何为这个词做所有的事情。.Field(nameof(Toppings),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validate: async (state, value) =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var values = ((List<object>)value).OfType<ToppingOptions>();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = new ValidateResult { IsValid = true, Value = values };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (values != null && values.Contains(ToppingOptions.everything))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.Value = (from ToppingOptions topping in Enum.GetValues(typeof(ToppingOptions))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; where topping != ToppingOptions.everything && !values.Contains(topping)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select topping).ToList();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = result.Value;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return result;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })
打开App,查看更多内容
随时随地看视频慕课网APP