Metoda CodeClass.AddImplementedInterface —

Dodaje interfejs do listy obiektów dziedziczone.

Przestrzeń nazw:  EnvDTE
Zestaw:  EnvDTE (w EnvDTE.dll)

Składnia

'Deklaracja
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

  • Base
    Typ: Object

    Wymagane.Interfejs klasy wprowadzi w życie.Jest to CodeInterface lub w pełni kwalifikowaną wpisz nazwę.

  • Position
    Typ: Object

    Opcjonalne.Domyślnie = 0.Element kodu, po którym ma być dodany nowy element.Jeśli wartość jest CodeElement, a następnie dodaje się nowy element natychmiast po.

    Jeśli wartość jest długi, następnie AddImplementedInterface wskazuje element, po którym ma być dodany nowy element.

    Ponieważ zbiory rozpocząć ich licznik na 1, przekazując 0 wskazuje, że nowy element powinien być umieszczony na początku kolekcji.Wartość-1 oznacza element powinny być umieszczane na końcu.

Wartość zwracana

Typ: EnvDTE.CodeInterface
A CodeInterface object.

Uwagi

AddImplementedInterfacedodaje się odwołania do interfejsu, który CodeClass implementuje.AddImplementedInterfacenie wstawiać metoda procedur wejścia dla członków interfejsu.

Visual C++ wymaga rozdzielone dwukropkiem (::) format dla jego typu w pełni kwalifikowanej nazwy.Innych języków obsługuje format oddzielonych od siebie kropkami.

Poprawność argumentów jest określana przez język za model kodu.

[!UWAGA]

Po dokonaniu niektórych rodzajów modyfikacji, co oznacza, że ich wartości nie może polegać na zawsze pozostawać taki sam może być nie deterministyczny wartości elementów modelu kodu, takich jak klasy, strukturach, funkcje, atrybuty, delegatów i tak dalej.Aby uzyskać więcej informacji, zobacz sekcję wartości elementu modelu kod można zmienić w Odnajdowanie kodu za pomocą modelu kodu (Visual Basic).

Przykłady

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

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

CodeClass Interfejs

Przestrzeń nazw EnvDTE

Inne zasoby

Porady: kompilowanie i uruchamianie kodu modelu obiektów automatyzacji — przykłady

Odnajdowanie kodu za pomocą modelu kodu (Visual Basic)

Odnajdowanie kodu za pomocą modelu kodu (Visual C#)