一旦已知特定变量类型,如何让 IntelliSense 更改列表成员?

How do I make IntelliSense change the list members once the specific variable type is known?

我正在使用 VB.net 在 Visual Studio 中为 Autodesk Inventor 编写插件。有许多不同类型的文档。当我知道文档的类型时,我希望 IntelliSense 列出该文档的成员。如果没有 Dim-ing 一个全新的变量,有没有办法做到这一点?

Sub Test(o_Doc As Inventor.Document)

    Select Case True
        Case TypeOf o_Doc Is AssemblyDocument, TypeOf o_Doc Is PartDocument
            o_Doc.  ' Intellisense lists the members for Inventor.Document
    End Select

End Sub

输入 o_Doc 后,我按句号,它会列出 Inventor.Document 的成员。 AssemblyDocumentPartDocument 都共享一个 ComponentDefinition 成员,但并非所有类型的文档都如此。有没有办法列出 AssemblyDocument 的所有成员,而不必在 Case 运算符之后插入它?

Dim _AssemblyDocument as Inventor.AssemblyDocument= o_Doc
_AssemblyDocument. ' lists all the members of AssemblyDocument

编辑:将 Dim _AssemblyDocument Inventor.Document 更改为 AssemblyDocument

我想说不,但从技术上讲,如果您只是在寻找一种无需声明新变量即可获得智能感知的方法,您可以强制转换,

Sub Test(o_Doc As Inventor.Document)
    Select Case True
        Case TypeOf o_Doc Is AssemblyDocument
            DirectCast(o_Doc, AssemblyDocument). ' AssemblyDocument intellisense
        Case TypeOf o_Doc Is PartDocument
            ' or if you access more than one member, With might be easier
            With DirectCast(o_Doc, PartDocument)
                . ' PartDocument intellisense 1
                . ' PartDocument intellisense 2
            End With
    End Select
End Sub

但现在你有不同的案例。

再问一次,继承链中还有另一个class吗?

  • Inventor.Document
    • 另一个Class/接口
      • 程序集文档
      • 零件文档

我发现派生的 classes 会共享未在其基 class 或接口中声明的成员,这很奇怪。如果它们确实共享另一个公共 class 或接口,那么您可以对其进行测试并转换为它,并且这两种类型只有一个案例。