Home > database >  How Do I convert C# Object Cast to VB.net Object Cast?(Specific Cast Method Shown)
How Do I convert C# Object Cast to VB.net Object Cast?(Specific Cast Method Shown)

Time:10-23

I'm working on getting the code below converted to VB.Net. What am I doing wrong here?

Code: Here is what I tried below. I tried Converting the following Statement:

(gotoAction.Destination, PDFPageDirectDestination).Page = destinationPage
            bookmark.Action = gotoAction

To this statement in the following Function: (I used DirectCast)

 Public Shared Function CreateBookmark(title As String, bookmarkColor As PDFRgbColor, visualStyle As PDFOutlineItemVisualStyle, destinationPage As PDFPage) As PDFOutlineItem

           
            Dim bookmark As PDFOutlineItem = New PDFOutlineItem()
            bookmark.Title = title
            bookmark.Color = bookmarkColor
           
            bookmark.VisualStyle = visualStyle

            Dim gotoAction As PDFGoToAction = New PDFGoToAction()
            
            gotoAction.Destination = New PDFPageDirectDestination()
            
            DirectCast(gotoAction.Destination, PDFPageDirectDestination).Page = destinationPage
            bookmark.Action = gotoAction

            Return bookmark
        End Function

CodePudding user response:

Try this, no casting needed:

Public Shared Function CreateBookmark(title As String, bookmarkColor As PDFRgbColor, visualStyle As PDFOutlineItemVisualStyle, destinationPage As PDFPage) As PDFOutlineItem          
     Dim bookmark As New PDFOutlineItem()
     bookmark.Title = title
     bookmark.Color = bookmarkColor          
     bookmark.VisualStyle = visualStyle

     Dim gotoAction As New PDFGoToAction()   
     Dim destination As New PDFPageDirectDestination()                   
     destination.Page = destinationPage
     gotoAction.Destination = destination
     bookmark.Action = gotoAction

     Return bookmark
End Function
  • Related