Sdílet prostřednictvím


CodeClass2.AddImplementedInterface – metoda (Object, Object)

Přidá do seznamu zděděných objektů rozhraní.

Obor názvů:  EnvDTE80
Sestavení:  EnvDTE80 (v EnvDTE80.dll)

Syntaxe

'Deklarace
Function AddImplementedInterface ( _
    Base As Object, _
    Position As Object _
) As CodeInterface
CodeInterface AddImplementedInterface(
    Object Base,
    Object Position
)
CodeInterface^ AddImplementedInterface(
    Object^ Base, 
    Object^ Position
)
abstract AddImplementedInterface : 
        Base:Object * 
        Position:Object -> CodeInterface 
function AddImplementedInterface(
    Base : Object, 
    Position : Object
) : CodeInterface

Parametry

  • Position
    Typ: System.Object
    Nepovinné.Výchozí nastavení = 0.Prvek kódu, po které budou nové rozhraní.
    Jestliže hodnota bude typ dat Long Position určuje prvek, po které chcete přidat nový prvek.
    Protože kolekce zahájit jejich počet na 1, procházející 0 udává, že nový prvek by měl na začátku kolekce.Hodnota-1 znamená prvek je umístit na konci.

Vrácená hodnota

Typ: EnvDTE.CodeInterface
A CodeInterface objektu.

Implementuje

CodeClass.AddImplementedInterface(Object, Object)

Poznámky

AddImplementedInterfacePřidá odkaz na rozhraní, které CodeClass2 objekt implementuje. AddImplementedInterfaceVložit objekty stub metodu pro členy rozhraní.

Nativní Visual C++ vyžaduje oddělené dvojtečkou (::) formát pro jeho úplný zadejte jména. Všechny jazyky podporují formát oddělených tečkami.

Správnosti argumentů je určen jazyk za modelu kódu.

Poznámka

Deterministický může být po provedení určité typy úprav, což znamená, že jejich hodnoty nelze dovolávat vždy zůstat stejné hodnoty prvků modelu kód jako třídy, struktury, funkce, atributy, delegátů a tak dále. Další informace naleznete v části Změna hodnoty prvku modelu kódu Discovering Code by Using the Code Model (Visual Basic).

Příklady

Visual Basic

Sub AddImplementedInterfaceExample(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 cm As CodeModel = _
            cls.ProjectItem.ContainingProject.CodeModel

        ' Add a new implemented interface to the class.
        cls.AddImplementedInterface(ConvertFullName(cm, _
            "System.IDisposable"))
    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

[C#]

public void AddImplementedInterfaceExample(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);
        CodeModel cm = cls.ProjectItem.ContainingProject.CodeModel;

        // Add a new implemented interface to the class.
        cls.AddImplementedInterface(ConvertFullName(cm, 
            "System.IDisposable"), -1);
    }
    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;
}

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

CodeClass2 Rozhraní

AddImplementedInterface – přetížení

EnvDTE80 – obor názvů

Další zdroje

How to: Compile and Run the Automation Object Model Code Examples

Discovering Code by Using the Code Model (Visual Basic)

Discovering Code by Using the Code Model (Visual C#)