Share via


CodeClass2.IsAbstract 屬性

設定或取得某一程式碼類別是否宣告為抽象。

命名空間:  EnvDTE80
組件:  EnvDTE80 (在 EnvDTE80.dll 中)

語法

'宣告
Property IsAbstract As Boolean
    Get
    Set
bool IsAbstract { get; set; }
property bool IsAbstract {
    bool get ();
    void set (bool value);
}
abstract IsAbstract : bool with get, set
function get IsAbstract () : boolean
function set IsAbstract (value : boolean)

屬性值

型別:System.Boolean
布林值,如果程式碼類別宣告為抽象,則為 true,否則為 false。

實作

CodeClass.IsAbstract

備註

IsAbstract 屬性可傳回或設定該類別目前是否顯示為抽象,或者類別是否需要一個子類別 (Subclass) 將因抽象方法而遺漏的方法實作加入。 對於某些程式語言而言,這可能永遠都是 false。

注意事項注意事項

類別可能沒有宣告為抽象,但它有可能是隱含為抽象。

另外像是類別、建構、函式、屬性 (Attribute)、委派 (Delegate) 等這些程式碼模型元素的值,在經過特定方式的編輯之後也可以為非決定性,即表示這些值將不再固定。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。

範例

[Visual Basic]

Sub IsAbstractExample(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
        ' Retrieve the CodeClass at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim cls As CodeClass = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementClass), CodeClass)

        ' Display whether the class is abstract.
        If cls.IsAbstract Then
            MsgBox(cls.Name & " is an abstract class.")
        Else
            MsgBox(cls.Name & " is not an abstract class.")
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

[C#]

public void IsAbstractExample(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside a class definition.
    try
    {
        // Retrieve the CodeClass at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeClass cls = 
            (CodeClass)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementClass);

        // Display whether the class is abstract.
        if (cls.IsAbstract)
            MessageBox.Show(cls.Name + " is an abstract class.");
        else
            MessageBox.Show(cls.Name + " is not an abstract class.");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

CodeClass2 介面

IsAbstract 多載

EnvDTE80 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例

使用程式碼模型探索程式碼 (Visual Basic)

使用程式碼模型探索程式碼 (Visual C#)