Compartir a través de


CodeFunction.CanOverride Property

Sets or gets whether or not the function can be overridden.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Syntax

'Declaration
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)

Property Value

Type: System.Boolean
A Boolean value indicating true if the function can be overriden; false if otherwise.

Remarks

For Visual Basic, the function was declared with MustOverride or Overrideable.

For Visual C# and Visual C++, the function was declared with the virtual keyword.

For JScript, the function was not declared with the static or final keywords; that is, the methods can be implicitly overridden.

Note

The values of code model elements such as classes, structs, functions, attributes, delegates, and so forth can be non-deterministic after making certain kinds of edits, meaning that their values cannot be relied upon to always remain the same. For more information, see the section Code Model Element Values Can Change in Discovering Code by Using the Code Model (Visual Basic).

Examples

 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 Security

See Also

Reference

CodeFunction Interface

EnvDTE Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples

Discovering Code by Using the Code Model (Visual Basic)

Discovering Code by Using the Code Model (Visual C#)