我正在轉換這個 C# 行
return await _serviceUrl.WithOAuthBearerToken(bearerToken)
.AppendPathSegment($"api/v1/accounts/{accountId}/identities/{identityId}")
.AllowAnyHttpStatus()
.PatchJsonAsync(model)
.As<Models.IdentityModel>();
到 VB .Net 中的這一行
Return Await _serviceUrl.WithOAuthBearerToken(bearerToken).AppendPathSegment($"api/v1/accounts/{accountId}/identities/{identityId}").AllowAnyHttpStatus().PatchJsonAsync(model).[As](Of Identity)()
但我得到了這個錯誤
“As”不是“Task(Of IFlurlResponse)”的成員。
我如何解決它?
預先感謝
uj5u.com熱心網友回復:
直接翻譯是:
Return (Await _serviceUrl.WithOAuthBearerToken(bearerToken) _
.AppendPathSegment($"api/v1/accounts/{accountId}/identities/{identityId}") _
.AllowAnyHttpStatus() _
.PatchJsonAsync(model) _
).As(Of Identity)()
但我剛剛拿出了一個使用 Flurl 的專案,它似乎不包括在內As,所以我猜這是其他東西的一些擴展..
長話短說,當您有一個以 Async 結尾并回傳可等待的方法名稱時,如果您想鏈接,請在呼叫更多方法(在括號上)之前在括號內等待它
Dim r = (Await(Await(Await x.AAsync()).BAsync()).CAsync()).D
簡單地說,如果 aMethodAsync()回傳 a Task(Of X)then 呼叫Await MethodAsync()給你 X,否則你在 Task 上呼叫方法,而不是 X
腳注:
雖然必須使用方括號[As]來定義名為 As 的方法,但不必讓它們呼叫它
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/415365.html
標籤:
