ClassInterfaceType Enum

Definisi

Mengidentifikasi jenis antarmuka kelas yang dihasilkan untuk kelas.

public enum class ClassInterfaceType
public enum ClassInterfaceType
[System.Serializable]
public enum ClassInterfaceType
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum ClassInterfaceType
type ClassInterfaceType = 
[<System.Serializable>]
type ClassInterfaceType = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ClassInterfaceType = 
Public Enum ClassInterfaceType
Warisan
ClassInterfaceType
Atribut

Bidang

AutoDispatch 1

Menunjukkan bahwa kelas hanya mendukung pengikatan terlambat untuk klien COM. dispinterface untuk kelas secara otomatis diekspos ke klien COM berdasarkan permintaan. Pustaka jenis yang dihasilkan oleh Tlbexp.exe (Pengekspor Pustaka Jenis) tidak berisi informasi jenis untuk dispinterface mencegah klien membuat cache DISPID antarmuka. dispinterface tidak menunjukkan masalah penerapan versi yang dijelaskan karena ClassInterfaceAttribute klien hanya dapat mengikat akhir ke antarmuka.

Ini adalah pengaturan default untuk ClassInterfaceAttribute.

AutoDual 2

Menunjukkan bahwa antarmuka kelas ganda secara otomatis dihasilkan untuk kelas dan diekspos ke COM. Informasi jenis diproduksi untuk antarmuka kelas dan diterbitkan di pustaka jenis. Penggunaan AutoDual sangat tidak disarankan karena keterbatasan penerapan versi yang dijelaskan dalam ClassInterfaceAttribute.

None 0

Menunjukkan bahwa tidak ada antarmuka kelas yang dihasilkan untuk kelas . Jika tidak ada antarmuka yang diimplementasikan secara eksplisit, kelas hanya dapat menyediakan akses yang terlambat terikat melalui IDispatch antarmuka. Ini adalah pengaturan yang direkomendasikan untuk ClassInterfaceAttribute. Menggunakan ClassInterfaceType.None adalah satu-satunya cara untuk mengekspos fungsionalitas melalui antarmuka yang diimplementasikan secara eksplisit oleh kelas .

Tlbexp.exe (Pengekspor Pustaka Jenis) mengekspos antarmuka publik pertama yang terlihat COM yang diimplementasikan oleh kelas sebagai antarmuka default coclass. Dalam .NET Framework 2.0 dan versi yang lebih baru, Anda dapat menentukan antarmuka default yang diekspos ke COM dengan menggunakan ComDefaultInterfaceAttribute atribut . Jika kelas tidak mengimplementasikan antarmuka, antarmuka publik pertama yang terlihat COM yang diimplementasikan oleh kelas dasar menjadi antarmuka default (dimulai dengan kelas dasar turunan terbaru dan bekerja mundur). Tlbexp.exe diekspos _Object sebagai antarmuka default jika kelas maupun kelas dasarnya tidak mengimplementasikan antarmuka.

Contoh

Contoh ini menunjukkan cara menerapkan ke ClassInterfaceAttribute jenis, mengatur ClassInterfaceType. Kelas yang ditentukan dengan cara ini dapat digunakan dari COM yang tidak dikelola.

using namespace System;
using namespace System::Runtime::InteropServices;

// Have the CLR expose a class interface (derived from IDispatch)
// for this type. COM clients can call the  members of this
// class using the Invoke method from the IDispatch interface.
[ClassInterface(ClassInterfaceType::AutoDispatch)]
public ref class AClassUsableViaCOM
{
public:
    AClassUsableViaCOM() 
    { 
    }

public:
    int Add(int x, int y)
    {
        return x + y;
    }
};

// The CLR does not expose a class interface for this type.
// COM clients can call the members of this class using
// the methods from the IComparable interface.
[ClassInterface(ClassInterfaceType::None)]
public ref class AnotherClassUsableViaCOM : public IComparable
{
public:
    AnotherClassUsableViaCOM() 
    { 
    }

    virtual int CompareTo(Object^ o) = IComparable::CompareTo
    {
        return 0;
    }
};
using System;
using System.Runtime.InteropServices;

// Have the CLR expose a class interface (derived from IDispatch) for this type.
// COM clients can call the  members of this class using the Invoke method from the IDispatch interface.
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class AClassUsableViaCOM
{
    public AClassUsableViaCOM() { }

    public Int32 Add(Int32 x, Int32 y) { return x + y; }
}

// The CLR does not expose a class interface for this type.
// COM clients can call the members of this class using the methods from the IComparable interface.
[ClassInterface(ClassInterfaceType.None)]
public class AnotherClassUsableViaCOM : IComparable
{
    public AnotherClassUsableViaCOM() { }

    Int32 IComparable.CompareTo(Object o) { return 0; }
}
Imports System.Runtime.InteropServices


' Have the CLR expose a class interface (derived from IDispatch) for this type.
' COM clients can call the  members of this class using the Invoke method from the IDispatch interface.
<ClassInterface(ClassInterfaceType.AutoDispatch)> _
Public Class AClassUsableViaCOM

    Public Sub New()

    End Sub

    Public Function Add(ByVal x As Int32, ByVal y As Int32) As Int32
        Return x + y

    End Function
End Class
' The CLR does not expose a class interface for this type.
' COM clients can call the members of this class using the methods from the IComparable interface.
<ClassInterface(ClassInterfaceType.None)> _
Public Class AnotherClassUsableViaCOM
    Implements IComparable

    Public Sub New()

    End Sub

    Function CompareTo(ByVal o As [Object]) As Int32 Implements IComparable.CompareTo
        Return 0

    End Function 'IComparable.CompareTo
End Class

Keterangan

Enumerasi ini digunakan bersama dengan ClassInterfaceAttribute atribut .

Berlaku untuk

Lihat juga