CodeClass.IsCodeType 属性

定义

获取一个, CodeType 该值指示是否可以从此对象中获取对象。

public:
 property bool IsCodeType { bool get(); };
public:
 property bool IsCodeType { bool get(); };
[System.Runtime.InteropServices.DispId(6)]
public bool IsCodeType { [System.Runtime.InteropServices.DispId(6)] [System.Runtime.InteropServices.TypeLibFunc(1024)] get; }
[<System.Runtime.InteropServices.DispId(6)>]
[<get: System.Runtime.InteropServices.DispId(6)>]
[<get: System.Runtime.InteropServices.TypeLibFunc(1024)>]
member this.IsCodeType : bool
Public ReadOnly Property IsCodeType As Boolean

属性值

Boolean

一个布尔值,指示 true 是否 CodeType 可以获取对象,否则返回 false

属性

示例

Public Sub CodeClassExample(ByVal dte As DTE2)   
    ' Before running this example, open a code document from a  
    ' project and place the insertion point inside a class definition  
    Try  
        Dim objTextSel As TextSelection  
        Dim objCodeCls As CodeClass  
        Dim objCodeType As CodeType  
        Dim objCMElem As vsCMElement  
        objTextSel = CType(dte.ActiveDocument.Selection, TextSelection)  
        objCodeCls = CType(objTextSel.ActivePoint.CodeElement(vsCMElement.vsCMElementClass), CodeClass)  
        ' Add DocComment to CodeClass objCodeClass.  
        objCodeCls.DocComment = "<DOC>DocComment for the CodeClass object</DOC>"  
        MessageBox.Show(objCodeCls.DocComment)  
        ' Test if a CodeType object is obtainable from the CodeClass  
        If objCodeCls.IsCodeType Then  
            ' then we can cast the CodeClass to a CodeType.  
            objCodeType = CType(objCodeCls, CodeType)  
        Else  
            ' The CodeClass object is not a CodeType but is  
            ' some Kind of element.  
            objCMElem = objCodeCls.Kind  
        End If  
    Catch ex As Exception  
        MessageBox.Show(ex.Message)  
    End Try  
End Sub  
public void CodeClassExample(DTE2 dte)  
{   
   // Before running this example, open a code document from a  
   // project and place the insertion point inside a class definition  
   try  
   {  
      TextSelection objTextSel;  
      CodeClass objCodeCls;  
      CodeType objCodeType;  
      vsCMElement objCMElem;  
      objTextSel = (TextSelection)dte.ActiveDocument.Selection;  
      objCodeCls = (CodeClass)objTextSel.ActivePoint.get_CodeElement(vsCMElement.vsCMElementClass);  
      // Add DocComment to CodeClass objCodeClass.  
      objCodeCls.DocComment = "<DOC>DocComment for the CodeClass object</DOC>";  
      MessageBox.Show(objCodeCls.DocComment);  
      // Test if a CodeType object is obtainable from the CodeClass  
      if (objCodeCls.IsCodeType)  
      { // then we can cast the CodeClass to a CodeType.  
         objCodeType = (CodeType)objCodeCls;  
      }  
      else // The CodeClass object is not a CodeType but is  
      {    // some Kind of element.  
         objCMElem = objCodeCls.Kind;  
      }  
   }  
   catch (Exception ex)  
   {   
      MessageBox.Show(ex.Message);  
   }  
}  

注解

返回代码元素是否为代码类型。 如果是,则可以查询接口或将其转换为 CodeType 对象。 当为、、、或时,此值为 true Kind vsCMElementClass vsCMElementInterface vsCMElementDelegate vsCMElementStruct vsCMElementEnum

备注

在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。

适用于