.net sdk and visual basic


#1

Hi,

I’m having headache porting CS code into Basic in order to do trivial getdoc/insert into a bucket.
My bucket contains JSON docs and blobs. Because of those “variant” format, i’m not sure how to cast the document for the IBucket. In my current code, vs complains about unable to cast system.string into the “fichier” IDocumentResult
Any idea to circumvent/fix that ?
note : i’m not used of Interfaces in VB.

Imports Couchbase.Annotations
Imports Couchbase.Core
Imports Couchbase.Core.Buckets

Namespace CouchbaseVB.Grabber

    Public Class fichier
        Public dataset As Object
    End Class

    Public Class CBlinker

        Private UsedBucketName As String
        Private MyCouch As Couchbase.Cluster = New Couchbase.Cluster()
        Private MyBucket As IBucket

        Public Sub Open(bucketname As String)
            UsedBucketName = bucketname
            MyBucket = MyCouch.OpenBucket(bucketname)
        End Sub

        Public Sub Close()
            If MyCouch.IsOpen(UsedBucketName) Then
                MyCouch.CloseBucket(MyBucket)
            End If
        End Sub

        Public Function GetDoc(docid As String) As Object
            Dim tmp As Object

            tmp = MyBucket.GetDocument(Of fichier)(docid)
            If tmp.Success Then
                Return tmp.Value.dataset
            Else
                Return tmp.Message
            End If
        End Function

    End Class

End Namespace

#2

Well, i fixed it using the generic “Object” type…
Could the .NET sdk have VB samples too ?

[...]
    Public Function GetDoc(docid As String) As String
        Dim tmp As Object

        tmp = MyBucket.GetDocument(Of Object)(docid)
        If tmp.Success Then
            Return tmp.Content
        Else
            Return tmp.Message
        End If

    End Function
[...]

#3

In order to map your documents to a strongly typed object, you’ll need a class on the VB side that matches the structure of your document. Using the object Type will work, but it’s not very useful.

Thanks for the feedback, we’ll backlog and prioritize for the future.

-Jeff