Compartir a través de


CodeFunction.MustImplement (Propiedad)

Establece u obtiene si el elemento se ha declarado o no como abstracto y, por tanto, requiere una implementación.

Espacio de nombres:  EnvDTE
Ensamblado:  EnvDTE (en EnvDTE.dll)

Sintaxis

'Declaración
Property MustImplement As Boolean
    Get
    Set
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)

Valor de propiedad

Tipo: System.Boolean
Un valor Boolean que indica true si el método se ha declarado como abstracto y, por tanto, requiere una implementación; false de lo contrario.

Comentarios

MustImplement devuelve o establece si el método se ha implementado o si requiere una implementación en subclases. Observe que para algunos lenguajes esto podría ser siempre False y que establecer MustImplement podría producir errores, dependiendo del lenguaje.

Nota

Los valores de los elementos de modelo de código como clases, structs, funciones, atributos, delegados, etc., pueden ser no deterministas una vez realizados determinados tipos de modificaciones; esto significa que no se puede confiar en que sus valores se mantengan siempre igual. Para obtener más información, vea la sección Los valores de elementos de modelo de código pueden cambiar, en Detectar código utilizando el modelo de código (Visual Basic).

Ejemplos

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

Seguridad de .NET Framework

Vea también

Referencia

CodeFunction Interfaz

EnvDTE (Espacio de nombres)

Otros recursos

Cómo: Compilar y ejecutar los ejemplos de código del modelo de objetos de automatización

Detectar código utilizando el modelo de código (Visual Basic)

Detectar código utilizando el modelo de código (Visual C#)