Share via


CodeFunction2.MustImplement 屬性

取得或設定值,指出表示是否將項目宣告為抽象而因此需要實作。

命名空間:  EnvDTE80
組件:  EnvDTE80 (在 EnvDTE80.dll 中)

語法

'宣告
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)

屬性值

型別:System.Boolean
布林值,如果方法已宣告為抽象而因此需要實作,則為 true,否則為 false。

實作

CodeFunction.MustImplement

備註

MustImplement 可傳回或設定是否已實作該方法,或者它需要在子類別 (Subclass) 中實作。 請注意,對於某些程式語言而言,這一定會是 false,而且設定 MustImplement 可能會失敗;但實際情況需視程式語言而定。

注意事項注意事項

在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。

範例

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

.NET Framework 安全性

請參閱

參考

CodeFunction2 介面

MustImplement 多載

EnvDTE80 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例

使用程式碼模型探索程式碼 (Visual Basic)

使用程式碼模型探索程式碼 (Visual C#)