C# 方法IDialogStack.Wait的类型参数<;R>;(ResumeAfter<;R>;resume)无法从用法中推断
我在bot中使用了一个C# 方法IDialogStack.Wait的类型参数<;R>;(ResumeAfter<;R>;resume)无法从用法中推断,c#,botframework,botbuilder,C#,Botframework,Botbuilder,我在bot中使用了一个IDialog,bot框架通过context执行我的一个方法。Wait()通常有两个参数: public async Task MainScreenSelectionReceived(IDialogContext context, IAwaitable<IMessageActivity> argument) 因此,现在所有的context.Wait调用都显示为无效: 如果我从方法声明中删除第三个参数,该错误就会
IDialog
,bot框架通过context执行我的一个方法。Wait()
通常有两个参数:
public async Task MainScreenSelectionReceived(IDialogContext context,
IAwaitable<IMessageActivity> argument)
因此,现在所有的context.Wait
调用都显示为无效:
如果我从方法声明中删除第三个参数,该错误就会消失
Visual Studio显示的消息是:
无法从用法推断方法IDialogStack.Wait(ResumeAfter resume)的类型参数。尝试显式指定类型参数
我假设这意味着我应该调用
context.Wait
作为context.Wait
,但我不知道该写什么来代替什么 创建重载,而不是添加可选参数。您的方法签名现在不再满足所需的委托
例如:
public async Task MainScreenSelectionReceived(IDialogContext context,
IAwaitable<IMessageActivity> argument, bool doNotShowPrompt)
{
//Original code here
}
public async Task MainScreenSelectionReceived(IDialogContext context,
IAwaitable<IMessageActivity> argument)
{
return await MainScreenSelectionReceived(context, argument, false);
}
公共异步任务MainScreenSelectionReceived(IDialogContext上下文,
IAwaitable参数,bool doNotShowPrompt)
{
//这里是原始代码
}
公共异步任务MainScreenSelectionReceived(IDialogContext上下文,
(可等待参数)
{
return wait main screenselectionreceived(上下文、参数、false);
}
查看传递给context.Wait()
的委托的声明方式:
public delegate Task ResumeAfter<in T>(IDialogContext context, IAwaitable<T> result);
我不认为添加可选参数会使所有的等待都产生错误。你有没有做其他的改变?您可以发布方法MainScreenSelectionReceived的代码吗。@SethuBala当我从方法声明中删除第三个参数时,错误就会消失,但是我可以知道为什么不像问题中那样?是什么导致了这个问题?@SethuBala我不确定你的确切意思,为什么不确定问题中的什么?问题是因为该方法需要一个特定签名的委托。将参数添加到
MainScreenSelectionReceived
会更改签名,因此它不再满足委托签名。@Rob Dang。你说得对。我做的是与之相反的事情,用非默认值调用该方法的重载。更清楚地说,我很好奇为什么不更改原始方法本身的签名?等待错误的根本原因是什么?是的,现在我明白了。老实说,这是我后来实现的方法签名。谢谢@Rob
public delegate Task ResumeAfter<in T>(IDialogContext context, IAwaitable<T> result);
MainScreenSelectionReceived(IDialogContext context, IAwaitable<IMessageActivity> argument)
=> MainScreenSelectionReceived(context, argument, false);
MainScreenSelectionReceived(IDialogContext context, IAwaitable<IMessageActivity> argument,
bool doNotShowPrompt)
{
// Do stuff here
}
context.Wait((c, a) => MainScreenSelectionReceived(c, a, false));