CodeFunction.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 ключевыми словами или, т. е. методы могут быть неявно переопределены.

Примечание

Значения элементов модели кода, таких как классы, структуры, функции, атрибуты, делегаты и другие, после внесения некоторых изменений могут оказаться недетерминированными, другими словами, нельзя рассчитывать, что их значения будут всегда оставаться одинаковыми. Дополнительные сведения см. в разделе значения элементов модели кода могут изменяться при обнаружении кода с помощью модели кода (Visual Basic).

Применяется к