共用方式為


CodeClass.RemoveInterface 方法

從實作介面清單中移除介面。

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

語法

'宣告
Sub RemoveInterface ( _
    Element As Object _
)
void RemoveInterface(
    Object Element
)
void RemoveInterface(
    Object^ Element
)
abstract RemoveInterface : 
        Element:Object -> unit
function RemoveInterface(
    Element : Object
)

參數

  • Element
    類型:Object

    必要項。 CodeElement 或集合中某一項目的名稱。

備註

ImplementedInterfaces 集合中移除程式碼項目。 這個項目可以是集合中某個 CodeElement 物件,也可以是集合中某個唯一項目的名稱。

注意事項注意事項

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

範例

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

        If MsgBox("Remove all interfaces from " & cls.Name & "?", _
            MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            Dim intrface As CodeElement
            For Each intrface In cls.ImplementedInterfaces
                cls.RemoveInterface(intrface)
            Next
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Function ConvertFullName(ByVal cm As CodeModel, _
    ByVal fullName As String) As String

    ' Convert a .NET type name into a C++ type name.
    If (cm.Language = CodeModelLanguageConstants.vsCMLanguageVC) Or _
        (cm.Language = CodeModelLanguageConstants.vsCMLanguageMC) Then
        Return fullName.Replace(".", "::")
    Else
        Return fullName
    End If

End Function
public void RemoveInterfaceExample(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);

        if (MessageBox.Show("Remove all interfaces from " + cls.Name + 
            "?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            foreach (CodeInterface intrface in 
                cls.ImplementedInterfaces)
                cls.RemoveInterface(intrface);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

string ConvertFullName(CodeModel cm, string fullName)
{
    // Convert a .NET type name into a C++ type name.
    if ((cm.Language == CodeModelLanguageConstants.vsCMLanguageVC) || 
        (cm.Language == CodeModelLanguageConstants.vsCMLanguageMC))
        return fullName.Replace(".", "::");
    else
        return fullName;
}

.NET Framework 安全性

請參閱

參考

CodeClass 介面

EnvDTE 命名空間

其他資源

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

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

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