Translate Code Snippet from C# to VB
I need to translate line 4 in the code snippet below into VB. For some reason I cannot get this done tonight. I am either too tired or having a brain drain... Can you help?
var provider = new NativeApp开发者_StackOverflowlicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = ClientCredentials.ClientID;
provider.ClientSecret = ClientCredentials.ClientSecret;
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);
Translation tools have gotten me this far, but it's not right.
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)
The GetAuthorization method has the following signature.
Private Function GetAuthorization(ByVal arg As NativeApplicationClient) As IAuthorizationState
You need AddressOf
Dim auth As OAuth2Authenticator(Of NativeApplicationClient) = New OAuth2Authenticator(Of NativeApplicationClient)(provider, AddressOf GetAuthorization)
Refer to this Website for the Translation of any code from C# to VB and the code after conversion is
Dim provider = New NativeApplicationClient(GoogleAuthenticationServer.Description)
provider.ClientIdentifier = ClientCredentials.ClientID
provider.ClientSecret = ClientCredentials.ClientSecret
Dim auth = New OAuth2Authenticator(Of NativeApplicationClient)(provider, GetAuthentication)
You are trying to use OAuth2Authenticator to GetAuthorization and the two are different, maybe that's your problem.
AddressOf never calls the function, you need to use
Dim getAuth As Func(Of NativeApplicationClient, IAuthorizationState) = AddressOf GetAuthorization
Dim auth As New OAuth2Authenticator(Of NativeApplicationClient)(provider, getAuth)
精彩评论