我一直收到此错误,不确定如何纠正
I keep getting this error and not sure how to correct it
错误1无法将回调用作动态参数分派的操作,因为它是一个方法组。您是否打算调用该方法?
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) { }
推荐答案
问题在于此调用是动态的:
The problem is that this call is dynamic:
userService.SignIn(openId, email, Callback);必须是,因为 openId 和电子邮件推断为动态类型:
It has to be, because openId and email are inferred to be of type dynamic:
var openId = meResult.id; var email = meResult.emails.preferred;在动态调用中不能使用这样的方法组转换-这只是其中之一限制使用 dynamic 。
You can't use a method group conversion like this in a dynamic call - it's just one of the restrictions of using dynamic.
因此,选项:
-
给出 openId 和 email 显式类型,如果( userService 不是动态的 )将使调用变为非动态的,方法组转换将在此调用进行。这只是意味着要明确指定类型,因为 dynamic 有一个隐式转换:
Give openId and email explicit types, which (if userService isn't dynamic) will make the call non-dynamic, at which the method group conversion will work. This just means specifying the types explicitly, as there's an implicit conversion available from dynamic:
从<$ c创建一个特定的委托类型实例$ c>回调方法,如果要保持 SignIn 调用动态:
Create a specific delegate type instance from the Callback method, if you want to keep the SignIn call dynamic:
var openId = meResult.id; var email = meResult.emails.preferred; // Or use whichever delegate type is actually appropriate for SignIn userService.SignIn(openId, email, new Action<ErrorModel>(Callback));
更多推荐
如何使用动态回调?
发布评论