
Error 1 Cannot use ‘Callback’ as an argument to a dynamically
dispatched operation because it is a method group. DID you intend to
invoke the method?
//... if (e.Status == liveConnectSessionStatus.Connected) { clIEnt = new liveConnectClIEnt(e.Session); liveOperationResult operationResult = await clIEnt.GetAsync("me"); try { dynamic meResult = operationResult.Result; var openID = meResult.ID; var email = meResult.emails.preferred; //MessageBox.Show(openID); //MessageBox.Show(email); userService.SignIn(openID,email,Callback); } catch (liveConnectException exception) { MessageBox.Show("Error calling API: " + exception.Message); } }}private voID Callback(ErrorModel error){ if (error != null) { MessageBox.Show(error.FrIEndlyErrorMsg,error.Caption,MessageBoxbutton.OK); } else { }}public voID SignIn(string ID,string email,Action<ErrorModel> callBack){}解决方法 问题是这个调用是动态的: userService.SignIn(openID,Callback);
它必须是,因为openID和email被推断为动态类型:
var openID = meResult.ID;var email = meResult.emails.preferred;
您不能在动态调用中使用这样的方法组转换 – 这只是使用动态的限制之一.
所以,选项:
>提供openID和电子邮件显式类型(如果userService不是动态的)将使调用非动态,方法组转换将起作用.这只是意味着明确指定类型,因为动态可以使用隐式转换:
string openID = meResult.ID;string email = meResult.emails.preferred;userService.SignIn(openID,Callback);
>如果要保持SignIn调用动态,请从Callback方法创建特定的委托类型实例:
var openID = meResult.ID;var email = meResult.emails.preferred;// Or use whichever delegate type is actually appropriate for SignInuserService.SignIn(openID,new Action<ErrorModel>(Callback));总结
以上是内存溢出为你收集整理的c# – 如何使用Dynamic进行回调?全部内容,希望文章能够帮你解决c# – 如何使用Dynamic进行回调?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)