Compartir a través de


CodeFunction2.MustImplement Property

Definition

Gets or sets a value indicating whether or not the item is declared abstract and thus requires an implementation.

public:
 property bool MustImplement { bool get(); void set(bool value); };
public:
 property bool MustImplement { bool get(); void set(bool value); };
[System.Runtime.InteropServices.DispId(41)]
public bool MustImplement { [System.Runtime.InteropServices.DispId(41)] get; [System.Runtime.InteropServices.DispId(41)] set; }
[<System.Runtime.InteropServices.DispId(41)>]
[<get: System.Runtime.InteropServices.DispId(41)>]
[<set: System.Runtime.InteropServices.DispId(41)>]
member this.MustImplement : bool with get, set
Public Property MustImplement As Boolean

Property Value

A Boolean that is true if the method is declared abstract and thus requires an implementation; otherwise, false.

Implements

Attributes

Examples

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

Remarks

MustImplement returns or sets whether the method is implemented or requires an implementation in subclasses. Note that for some languages this might always be false, and that setting MustImplement might fail, depending on the language.

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.

Applies to