Search code examples
c#vb.netcode-translation

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 NativeApplicationClient(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

Solution

  • You need AddressOf

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