다음을 통해 공유


ClassInterfaceAttribute 클래스

COM에 노출될 클래스에 대해 생성될 클래스 인터페이스의 형식을 나타냅니다(인터페이스가 생성되는 경우).

네임스페이스: System.Runtime.InteropServices
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class, Inherited:=False)> _
Public NotInheritable Class ClassInterfaceAttribute
    Inherits Attribute
‘사용 방법
Dim instance As ClassInterfaceAttribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false)] 
public sealed class ClassInterfaceAttribute : Attribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class, Inherited=false)] 
public ref class ClassInterfaceAttribute sealed : public Attribute
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false) */ 
public final class ClassInterfaceAttribute extends Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false) 
public final class ClassInterfaceAttribute extends Attribute

설명

이 특성은 어셈블리 또는 클래스에 적용될 수 있습니다.

이 특성은 형식 라이브러리 내보내기(Tlbexp.exe)가 특성 사용 클래스에 대해 클래스 인터페이스를 자동으로 생성할지 여부를 제어합니다. 클래스 인터페이스는 클래스 자체와 동일한 이름을 가지지만 맨 앞에 밑줄이 붙습니다. 클래스 인터페이스는 기본 클래스에서 상속된 멤버를 포함하여 관리되는 클래스의 static이 아닌 public 멤버를 모두 포함합니다. 관리되는 클래스는 클래스 인터페이스에 액세스할 수 없지만, 클래스 멤버에 직접 액세스할 수 있으므로 클래스 인터페이스에는 액세스할 필요가 없습니다. Tlbexp.exe는 클래스 인터페이스에 대한 고유 IID(Interface Identifier)를 생성합니다.

클래스 인터페이스는 이중 인터페이스이거나 디스패치 전용 인터페이스입니다. 클래스 인터페이스가 생성되지 않도록 하고 대신 사용자 지정 인터페이스를 제공할 수도 있습니다. System.Runtime.InteropServices.ClassInterfaceType 열거형 멤버를 지정하여 클래스 인터페이스를 노출시키거나 숨길 수 있습니다. ClassInterfaceAttribute를 어셈블리에 적용할 때는 어셈블리의 개별 클래스가 자신의 특성으로 해당 설정을 재정의하는 경우가 아니면 이 특성이 어셈블리의 모든 클래스에 적용됩니다.

클래스 인터페이스의 경우 각 클래스에 대해 명시적으로 인터페이스를 정의할 필요가 없지만 프로덕션 응용 프로그램에서는 사용하지 않는 것이 좋습니다. 이중 클래스 인터페이스의 경우, 클래스가 변경되면 따라서 변경되는 특정 인터페이스 레이아웃에 클라이언트가 바인딩될 수 있습니다. 예를 들어, COM 클라이언트에 클래스 인터페이스를 노출시키는 관리되는 클래스가 있다고 가정합니다. 첫 번째 버전의 클래스에는 메서드 NorthSouth가 있습니다. 관리되지 않는 클라이언트가 클래스 인터페이스의 첫 번째 메서드로 North를, 두 번째 메서드로 South를 제공하는 클래스 인터페이스에 바인딩될 수 있습니다. 그리고 다음 버전의 클래스에는 NorthSouth 사이에 새로운 메서드 East가 삽입되었다고 가정합니다. 이전 클래스 인터페이스를 통해 새 클래스에 바인딩하려는 관리되지 않는 클라이언트는 인터페이스에서 해당 메서드 위치가 변경되었으므로 메서드 South를 호출하려고 할 때 결과적으로 메서드 East를 호출하게 됩니다. 또한 기본 클래스의 레이아웃이 변경되면 파생된 모든 클래스에 대한 클래스 인터페이스의 레이아웃도 영향을 받습니다. 클래스에 직접 바인딩되는 관리되는 클라이언트를 사용하면 이러한 버전 관리 문제가 발생하지 않습니다. 클래스 인터페이스 사용에 대한 자세한 지침은 클래스 인터페이스 소개를 참조하십시오.

형식 라이브러리 가져오기(Tlbimp.exe)는 항상 가져온 클래스에 ClassInterfaceType.None 열거형 멤버를 적용하여 기존 COM 클래스가 관리되는 인터페이스를 노출시키지 않는다는 것을 나타냅니다.

예제

다음 예제에서는 MyClass에 대해 IDispatch 인터페이스를 생성하는 ClassInterfaceTypeAutoDispatch를 사용하여 ClassInterfaceAttribute를 적용하는 방법을 보여 줍니다.

Imports System.Runtime.InteropServices

<ClassInterface(ClassInterfaceType.AutoDispatch)> _
Public Class SampleClass    
    ' Insert class members here.
End Class
using System.Runtime.InteropServices;

[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class MyClass
{
   public MyClass() {}
}
using namespace System::Runtime::InteropServices;

[ClassInterface(ClassInterfaceType::AutoDispatch)]
public ref class MyClass
{
public:
   MyClass(){}

};
import System.Runtime.InteropServices.*;

/** @attribute ClassInterface(ClassInterfaceType.AutoDispatch)
 */
public class MyClass
{
    public MyClass()
    {
    } //MyClass
} //MyClass 

상속 계층 구조

System.Object
   System.Attribute
    System.Runtime.InteropServices.ClassInterfaceAttribute

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원

참고 항목

참조

ClassInterfaceAttribute 멤버
System.Runtime.InteropServices 네임스페이스
ClassInterfaceType

기타 리소스

형식 라이브러리 내보내기(Tlbexp.exe)
형식 라이브러리 가져오기(Tlbimp.exe)