根据选择跳过问题
Skips questions depending on a choice
我想知道是否可以根据用户的选择,跳过所有问题并终止对话。
例如,我有下一个代码:
public ContentClassification ContentClassification {get;set;}
public StatusOfContent StatusContent {get; set;}
public Accessibility ExternalSharing {get; set;}
根据"ContentClassification"的选择,跳过其他问题。
提前致谢。
Depending on the choice of "ContentClassification", skip the other questions.
您可以使用FieldReflector实现您自己的IField
,例如:
public enum ContentClassification
{
Confidential_Restricted = 1,
Confidential_Secret = 2,
Public = 3,
Strictly_Confidential = 4,
help = 5
};
public enum StatusContent
{
Status1,
Status2
}
public enum Accessibility
{
Accessibility1,
Accessibility2
}
[Serializable]
public class Classification
{
public ContentClassification? Choice { get; set; }
public StatusContent? StatusOfContent { get; set; }
public Accessibility? Accessibility { get; set; }
public static bool Confirmation = true;
public static IForm<Classification> BuildForm()
{
return new FormBuilder<Classification>()
.Message("You want to")
.Field(new FieldReflector<Classification>(nameof(Choice))
.SetNext((value, state) =>
{
var selection = (ContentClassification)value;
if (selection == ContentClassification.help)
{
Confirmation = false;
state.Accessibility = null;
state.StatusOfContent = null;
}
else
{
Confirmation = true;
}
return new NextStep();
}))
.Field(new FieldReflector<Classification>(nameof(StatusOfContent))
.SetActive(state => Confirmation))
.Field(new FieldReflector<Classification>(nameof(Accessibility))
.SetActive(state => 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;
//TODO:
}
}
使用此代码,当用户 select Help
在第一个对话框 Choice
中时,它将跳过以下两个问题,您将在 GetResultAsync
与 Choice = Help
、StatusOfContent = null
、Accessibility = null
等。
我想知道是否可以根据用户的选择,跳过所有问题并终止对话。
例如,我有下一个代码:
public ContentClassification ContentClassification {get;set;}
public StatusOfContent StatusContent {get; set;}
public Accessibility ExternalSharing {get; set;}
根据"ContentClassification"的选择,跳过其他问题。
提前致谢。
Depending on the choice of "ContentClassification", skip the other questions.
您可以使用FieldReflector实现您自己的IField
,例如:
public enum ContentClassification
{
Confidential_Restricted = 1,
Confidential_Secret = 2,
Public = 3,
Strictly_Confidential = 4,
help = 5
};
public enum StatusContent
{
Status1,
Status2
}
public enum Accessibility
{
Accessibility1,
Accessibility2
}
[Serializable]
public class Classification
{
public ContentClassification? Choice { get; set; }
public StatusContent? StatusOfContent { get; set; }
public Accessibility? Accessibility { get; set; }
public static bool Confirmation = true;
public static IForm<Classification> BuildForm()
{
return new FormBuilder<Classification>()
.Message("You want to")
.Field(new FieldReflector<Classification>(nameof(Choice))
.SetNext((value, state) =>
{
var selection = (ContentClassification)value;
if (selection == ContentClassification.help)
{
Confirmation = false;
state.Accessibility = null;
state.StatusOfContent = null;
}
else
{
Confirmation = true;
}
return new NextStep();
}))
.Field(new FieldReflector<Classification>(nameof(StatusOfContent))
.SetActive(state => Confirmation))
.Field(new FieldReflector<Classification>(nameof(Accessibility))
.SetActive(state => 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;
//TODO:
}
}
使用此代码,当用户 select Help
在第一个对话框 Choice
中时,它将跳过以下两个问题,您将在 GetResultAsync
与 Choice = Help
、StatusOfContent = null
、Accessibility = null
等。