验证选择字段



我有一个具有枚举的属性,在我拥有" help"的枚举之一中,如果用户选择该选项,我想做两件事:1:1。2.询问用户是否想继续,或者他想离开。我不知道怎么做。非常感谢。

public enum ContentClassification
{
    Confidential_Restricted = 1 ,
    Confidential_Secret = 2,
    Public = 3,
    Strictly_Confidential = 4,
    help = 5
};

公共内容clastallification contentClassification {get;放;}

返回新FormBuilder() 。

您可以多次启动Form,这意味着,如果您从第一个Form获得"帮助"选择,请启动另一种表格以进行确认。

例如:

public enum ContentClassification
{
    Confidential_Restricted = 1,
    Confidential_Secret = 2,
    Public = 3,
    Strictly_Confidential = 4,
    help = 5
};
public enum Validating
{
    Continue,
    Leave
};
[Serializable]
public class Classification
{
    public ContentClassification? Choice;
    public static IForm<Classification> BuildForm()
    {
        return new FormBuilder<Classification>()
            .Message("You want to")
            .Field(nameof(Choice))
            .Build();
    }
    public Validating? Confirmation;
    public static IForm<Classification> BuildConfirmForm()
    {
        return new FormBuilder<Classification>()
            .Message("Send your message here")
            .Field(nameof(Confirmation))
            .Build();
    }
}

然后创建您的RootDialog,例如:

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        var form = new FormDialog<Classification>(new Classification(), Classification.BuildForm, FormOptions.PromptInStart, null);
        context.Call(form, this.GetResultAsync);
        return Task.CompletedTask;
    }

    private async Task GetResultAsync(IDialogContext context, IAwaitable<Classification> result)
    {
        var state = await result;
        if (state.Choice == ContentClassification.help)
        {
            var form = new FormDialog<Classification>(new Classification(), Classification.BuildConfirmForm, FormOptions.PromptInStart, null);
            context.Call(form, null); //change null to your result task here to handle the result.
        }
    }
}

您仍然需要与 GetResultAsync方法中其他选项的逻辑代码以及逻辑代码一起处理第二种形式BuildConfirmForm的结果。

相关内容

  • 没有找到相关文章

最新更新