将代码片段从C#转换为VB

时间:2011-09-29 06:03:38

标签: c# vb.net code-translation

我需要将下面代码段中的第4行翻译成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

4 个答案:

答案 0 :(得分:3)

您需要AddressOf

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

答案 1 :(得分:1)

有关从C#到VB的任何代码的转换,请参阅此Website  转换后的代码是

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

答案 2 :(得分:0)

AddressOf从不调用该函数,您需要使用

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

答案 3 :(得分:0)

您正在尝试使用OAuth2Authenticator进行GetAuthorization,这两者是不同的,也许这就是您的问题。