简体   繁体   English

如何将 C# Object Cast 转换为 VB.net Object Cast?(显示了特定的 Cast 方法)

[英]How Do I convert C# Object Cast to VB.net Object Cast?(Specific Cast Method Shown)

I'm working on getting the code below converted to VB.Net.我正在努力将下面的代码转换为 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)在以下函数中对此声明:(我使用了 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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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