2011-09-29 93 views
0

我需要將以下代碼段中的第4行翻譯爲VB。出於某種原因,我今晚無法完成這件事。我要麼太累了,要麼是人才流失......你能幫忙嗎?將代碼片段從C#轉換爲VB

var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); 
provider.ClientIdentifier = ClientCredentials.ClientID; 
provider.ClientSecret = ClientCredentials.ClientSecret; 
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication); 

翻譯工具已經讓我走了這麼遠,但它是不正確的。

Dim provider As NativeApplicationClient = New NativeApplicationClient(GoogleAuthenticationServer.Description) 
provider.ClientIdentifier = ClientCredentials.ClientID 
provider.ClientSecret = ClientCredentials.ClientSecret 
Dim auth As OAuth2Authenticator(Of NativeApplicationClient) = New OAuth2Authenticator(Of NativeApplicationClient)(provider, GetAuthorization) 

的GetAuthorization方法具有以下特徵。

Private Function GetAuthorization(ByVal arg As NativeApplicationClient) As IAuthorizationState 

回答

3

你需要AddressOf

Dim auth As OAuth2Authenticator(Of NativeApplicationClient) = New OAuth2Authenticator(Of NativeApplicationClient)(provider, AddressOf GetAuthorization) 
+0

我知道我錯過了一些簡單的事情。 :D謝謝! –

1

請參閱本Website對任何代碼的翻譯從C#到VB 和轉換後的代碼是

Dim provider = New NativeApplicationClient(GoogleAuthenticationServer.Description) 
provider.ClientIdentifier = ClientCredentials.ClientID 
provider.ClientSecret = ClientCredentials.ClientSecret 
Dim auth = New OAuth2Authenticator(Of NativeApplicationClient)(provider, GetAuthentication) 
+0

的DownVoters應該說一個原因? –

0

您正在嘗試使用OAuth2Authenticator到GetAuthorization和兩者是不同的,也許那是你的問題。

0

AddressOf從未調用該函數,你需要使用

Dim getAuth As Func(Of NativeApplicationClient, IAuthorizationState) = AddressOf GetAuthorization 
Dim auth As New OAuth2Authenticator(Of NativeApplicationClient)(provider, getAuth)