CodeFunction2.CanOverride 属性

定义

获取或设置是否可以重写此函数。

public:
 property bool CanOverride { bool get(); void set(bool value); };
public:
 property bool CanOverride { bool get(); void set(bool value); };
[System.Runtime.InteropServices.DispId(50)]
public bool CanOverride { [System.Runtime.InteropServices.DispId(50)] get; [System.Runtime.InteropServices.DispId(50)] set; }
[<System.Runtime.InteropServices.DispId(50)>]
[<get: System.Runtime.InteropServices.DispId(50)>]
[<set: System.Runtime.InteropServices.DispId(50)>]
member this.CanOverride : bool with get, set
Public Property CanOverride As Boolean

属性值

Boolean

如果可以重写此函数,则布尔值为 true;否则为 false

实现

属性

示例

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);  
    }  
}  

注解

  • 对于 Visual Basic,该函数是用或声明的 MustOverride Overrideable

  • 对于 Visual c # 和 Visual C++,函数是用关键字声明的 virtual

  • 对于 JScript,函数不是用 static 或关键字声明的 final ; 也就是说,可以隐式重写这些方法。

备注

在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。

适用于