Share via


Proprietà CodeFunction2.MustImplement

Ottiene o imposta un valore che indica se un elemento è dichiarato astratto e quindi richiede un'implementazione.

Spazio dei nomi:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Sintassi

'Dichiarazione
Property MustImplement As Boolean
bool MustImplement { get; set; }
property bool MustImplement {
    bool get ();
    void set (bool value);
}
abstract MustImplement : bool with get, set
function get MustImplement () : boolean
function set MustImplement (value : boolean)

Valore proprietà

Tipo: System.Boolean
Un valore booleano che viene true se il metodo viene dichiarato astratto e richiede un'implementazione; in caso contrario, false.

Note

MustImplement restituisce o imposta se il metodo viene distribuito o richiede un'implementazione in sottoclassi.Si noti che per alcuni linguaggi che potrebbe essere sempre falsee tale impostazione MustImplement potrebbe non riuscire, a seconda del linguaggio.

[!NOTA]

I valori degli elementi del modello di codice come classi, strutture, le funzioni, gli attributi, delegati, e così via possono non essere deterministici dopo l'inserimento di determinati tipi di modifiche, pertanto i relativi valori non possono essere basati su per rimanere sempre gli stessi.Per ulteriori informazioni, vedere i valori degli elementi del modello di codice della sezione può cambiare in Individuazione di codice mediante il modello di codice (Visual Basic).

Esempi

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

        Dim mustImpl As String
        Dim elem As CodeElement
        For Each elem In cls.Members
            If (elem.Kind = vsCMElement.vsCMElementFunction) Then
                Dim fun As CodeFunction = CType(elem, CodeFunction)
                If fun.MustImplement Then
                    mustImpl &= fun.Prototype( _
                        vsCMPrototype.vsCMPrototypeParamNames Or _
                        vsCMPrototype.vsCMPrototypeParamTypes Or _
                        vsCMPrototype.vsCMPrototypeType) & vbCrLf
                End If
            End If
        Next

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

End Sub
public void MustImplementExample(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);
        string mustImpl = "";

        foreach (CodeElement elem in cls.Members)
        {
            if (elem.Kind == vsCMElement.vsCMElementFunction)
            {
                CodeFunction fun = (CodeFunction)elem;

                if (fun.MustImplement)
                    mustImpl += fun.get_Prototype(
                        (int)(vsCMPrototype.vsCMPrototypeParamNames | 
                        vsCMPrototype.vsCMPrototypeParamTypes | 
                        vsCMPrototype.vsCMPrototypeType)) + "\n";
            }
        }

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

CodeFunction2 Interfaccia

Overload MustImplement

Spazio dei nomi EnvDTE80

Altre risorse

Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione

Individuazione di codice mediante il modello di codice (Visual Basic)

Individuazione di codice mediante il modello di codice (Visual C#)