CodeFunction.MustImplement-Eigenschaft

Aktualisiert: November 2007

Legt fest oder ruft ab, ob das Element als abstrakt deklariert ist und daher eine Implementierung erfordert.

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

Syntax

Property MustImplement As Boolean

Dim instance As CodeFunction
Dim value As Boolean

value = instance.MustImplement

instance.MustImplement = value
bool MustImplement { get; set; }
property bool MustImplement {
    bool get ();
    void set (bool value);
}
function get MustImplement () : boolean
function set MustImplement (value : boolean)

Eigenschaftenwert

Typ: System.Boolean

Ein boolescher Wert, der true lautet, wenn die Methode als abstrakt deklariert ist und eine Implementierung erfordert, und andernfalls false.

Hinweise

MustImplement gibt zurück oder legt fest, ob die Methode implementiert wurde oder eine Implementierung in Unterklassen erforderlich ist. Beachten Sie, dass dieser Wert in einigen Programmiersprachen immer False sein und das Festlegen von MustImplement je nach Sprache fehlschlagen kann.

Hinweis:

Die Werte von Codemodellelementen wie Klassen, Strukturen, Funktionen, Attributen, Delegaten usw. können nach bestimmten Bearbeitungsvorgängen nicht deterministisch sein, d. h., dass nicht mehr davon ausgegangen werden kann, dass ihre Werte immer unverändert bleiben. Weitere Informationen finden Sie im Abschnitt zum Änderungsverhalten von Codemodellelementwerten unter Ermitteln von Code über das Codemodell (Visual Basic).

Beispiele

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

Berechtigungen

Siehe auch

Referenz

CodeFunction-Schnittstelle

CodeFunction-Member

EnvDTE-Namespace

Weitere Ressourcen

Gewusst wie: Kompilieren und Ausführen der Codebeispiele für das Automatisierungsobjektmodell

Ermitteln von Code über das Codemodell (Visual Basic)

Ermitteln von Code über das Codemodell (Visual C#)