CodeFunction2.CanOverride 屬性

取得或設定是否能覆寫函式。

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

語法

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

屬性值

型別:System.Boolean
布林值,如果可以覆寫函式,則為 true,否則為 false。

實作

CodeFunction.CanOverride

備註

  • 對於 Visual Basic 而言,函式是以 MustOverrideOverrideable 宣告。

  • 至於 Visual C# 和 Visual C++,函式則是以 virtual 關鍵字宣告。

  • 就 JScript 而言,函式並不是以 static 或 final 關鍵字進行宣告 (也就是可隱含地覆寫方法)。

注意事項注意事項

在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。

範例

Sub CanOverrideExample(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)

        ' Find the class's overridable methods.
        Dim ovrrides As String
        Dim elem As CodeElement
        For Each elem In cls.Members
            If elem.Kind = vsCMElement.vsCMElementFunction AndAlso _
                CType(elem, CodeFunction).CanOverride Then
                ovrrides &= elem.Name & vbCrLf
            End If
        Next

        MsgBox(cls.Name & " has the following overridable methods:" & _
            vbCrLf & vbCrLf & ovrrides)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void CanOverrideExample(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);

        // Find the class's overridable methods.
        string overrides = "";
        
        foreach (CodeElement elem in cls.Members)
        {
            if ((elem.Kind == vsCMElement.vsCMElementFunction) && 
                ((CodeFunction)elem).CanOverride)
                overrides += elem.Name + "\r\n";
        }

        MessageBox.Show(cls.Name + 
            " has the following overridable methods:" + "\r\n\r\n" + 
            overrides);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

CodeFunction2 介面

CanOverride 多載

EnvDTE80 命名空間

其他資源

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

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

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