简体   繁体   中英

Error when converting C# to VB.NET in my windows phone project

I have been trying to convert some c# code to VB.NET for a while now. The purpose of this is that i am trying to build some kind of Twitter client, i have nearly converted all fo the following code for a class within my project, which is currently:

        Friend Shared Function GetRequestTokenQuery() As OAuthWebQuery
    Dim oauth = New OAuthWorkflow() With { _
        Key .ConsumerKey = AppSettings.consumerKey, _
        Key .ConsumerSecret = AppSettings.consumerKeySecret, _
        Key .SignatureMethod = OAuthSignatureMethod.HmacSha1, _
        Key .ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader, _
        Key .RequestTokenUrl = AppSettings.RequestTokenUri, _
        Key .Version = AppSettings.oAuthVersion, _
        Key .CallbackUrl = AppSettings.CallbackUri _
    }

        Dim info = oauth.BuildRequestTokenInfo(WebMethod.[Get])
        Dim objOAuthWebQuery = New OAuthWebQuery(info, False)
        objOAuthWebQuery.HasElevatedPermissions = True
        objOAuthWebQuery.SilverlightUserAgentHeader = "Hammock"
        Return objOAuthWebQuery
    End Function

However i then get the error 'Name of field or property being initialized in an object initializer must start with '.'' with the first mention of 'key' underlined in blue. Anyone got any ideas as to how i need to change my code?

The Correct syntax in VB.net would be like this

Friend Shared Function GetRequestTokenQuery() As OAuthWebQuery
    Dim oauth = New OAuthWorkflow() With { _
        .ConsumerKey = AppSettings.consumerKey, _
        .ConsumerSecret = AppSettings.consumerKeySecret, _
        .SignatureMethod = OAuthSignatureMethod.HmacSha1, _
        .ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader, _
        .RequestTokenUrl = AppSettings.RequestTokenUri, _
        .Version = AppSettings.oAuthVersion, _
        .CallbackUrl = AppSettings.CallbackUri _
    }

        Dim info = oauth.BuildRequestTokenInfo(WebMethod.[Get])
        Dim objOAuthWebQuery = New OAuthWebQuery(info, False)
        objOAuthWebQuery.HasElevatedPermissions = True
        objOAuthWebQuery.SilverlightUserAgentHeader = "Hammock"
        Return objOAuthWebQuery
    End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM