共用方式為


CodeFunction2.CanOverride 屬性

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

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

語法

'宣告
Property CanOverride As Boolean
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)

屬性值

類型:Boolean
布林值,如果可以覆寫函式則為 true;否則即為 false。

備註

  • 对于 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 介面

EnvDTE80 命名空間

其他資源

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

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

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