ExportAttribute 클래스

정의

형식, 속성, 필드 또는 메서드가 특정 내보내기를 제공하도록 지정합니다.

public ref class ExportAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)]
public class ExportAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)>]
type ExportAttribute = class
    inherit Attribute
Public Class ExportAttribute
Inherits Attribute
상속
ExportAttribute
파생
특성

예제

다음 예제에서는 데코레이트된 ExportAttribute클래스 3개와 해당 클래스와 일치하는 3개의 가져오기를 보여 줍니다.

//Default export infers type and contract name from the
//exported type.  This is the preferred method.
[Export]
public class MyExport1
{
    public String data = "Test Data 1.";
}

public class MyImporter1
{
    [Import]
    public MyExport1 importedMember { get; set; }
}

public interface MyInterface
{
}

//Specifying the contract type may be important if
//you want to export a type other then the base type,
//such as an interface.
[Export(typeof(MyInterface))]
public class MyExport2 : MyInterface
{
    public String data = "Test Data 2.";
}

public class MyImporter2
{
    //The import must match the contract type!
    [Import(typeof(MyInterface))]
    public MyExport2 importedMember { get; set; }
}

//Specifying a contract name should only be
//needed in rare caes. Usually, using metadata
//is a better approach.
[Export("MyContractName", typeof(MyInterface))]
public class MyExport3 : MyInterface
{
    public String data = "Test Data 3.";
}

public class MyImporter3
{
    //Both contract name and type must match!
    [Import("MyContractName", typeof(MyInterface))]
    public MyExport3 importedMember { get; set; }
}

class Program
{

    static void Main(string[] args)
    {
        AggregateCatalog catalog = new AggregateCatalog();
        catalog.Catalogs.Add(new AssemblyCatalog(typeof(MyExport1).Assembly));
        CompositionContainer _container = new CompositionContainer(catalog);
        MyImporter1 test1 = new MyImporter1();
        MyImporter2 test2 = new MyImporter2();
        MyImporter3 test3 = new MyImporter3();
        _container.SatisfyImportsOnce(test1);
        _container.SatisfyImportsOnce(test2);
        _container.SatisfyImportsOnce(test3);
        Console.WriteLine(test1.importedMember.data);
        Console.WriteLine(test2.importedMember.data);
        Console.WriteLine(test3.importedMember.data);
        Console.ReadLine();
    }
}
'Default export infers type and contract name from the
'exported type.  This is the preferred method.
<Export()>
Public Class MyExport1
    Public ReadOnly Property data As String
        Get
            Return "Test Data 1."
        End Get
    End Property
End Class

Public Class MyImporter1

    <Import()>
    Public Property ImportedMember As MyExport1

End Class

Public Interface MyInterface

End Interface

'Specifying the contract type may be important if
'you want to export a type other then the base type,
'such as an interface.
<Export(GetType(MyInterface))>
Public Class MyExport2
    Implements MyInterface
    Public ReadOnly Property data As String
        Get
            Return "Test Data 2."
        End Get
    End Property
End Class

Public Class MyImporter2
    'The import must match the contract type!
    <Import(GetType(MyInterface))>
    Public Property ImportedMember As MyExport2
End Class

'Specifying a contract name should only be 
'needed in rare caes. Usually, using metadata
'is a better approach.
<Export("MyContractName", GetType(MyInterface))>
Public Class MyExport3
    Implements MyInterface
    Public ReadOnly Property data As String
        Get
            Return "Test Data 3."
        End Get
    End Property
End Class

Public Class MyImporter3
    'Both contract name and type must match!
    <Import("MyContractName", GetType(MyInterface))>
    Public Property ImportedMember As MyExport3
End Class



Sub Main()
    Dim catalog As AggregateCatalog = New AggregateCatalog()
    catalog.Catalogs.Add(New AssemblyCatalog(GetType(MyExport1).Assembly))
    Dim container As CompositionContainer = New CompositionContainer(catalog)
    Dim test1 As MyImporter1 = New MyImporter1()
    Dim test2 As MyImporter2 = New MyImporter2()
    Dim test3 As MyImporter3 = New MyImporter3()
    container.SatisfyImportsOnce(test1)
    container.SatisfyImportsOnce(test2)
    container.SatisfyImportsOnce(test3)
    Console.WriteLine(test1.ImportedMember.data)
    Console.WriteLine(test2.ImportedMember.data)
    Console.WriteLine(test3.ImportedMember.data)
    Console.ReadLine()
End Sub

설명

특성 프로그래밍 모델 ExportAttribute 에서 파트가 특정 계약을 이행하는 개체인 컴퍼지션 컨테이너를 내보내거나 제공한다고 선언합니다. 컴퍼지션 중에 계약이 일치하는 가져오기가 있는 파트에는 내보낸 개체에 의해 채워진 종속성이 있습니다.

전체 ExportAttribute 클래스 또는 클래스의 속성, 필드 또는 메서드를 데코레이트할 수 있습니다. 전체 클래스가 데코레이팅된 경우 클래스의 인스턴스는 내보낸 개체입니다. 클래스의 멤버가 데코레이트된 경우 내보낸 개체는 데코레이팅된 멤버의 값이 됩니다.

계약 일치 여부는 주로 계약 이름 및 계약 유형에 따라 결정됩니다. 자세한 내용은 ImportAttribute를 참조하세요.

생성자

ExportAttribute()

이 특성으로 표시된 형식이나 멤버를 기본 계약 이름으로 내보내 ExportAttribute 클래스의 새 인스턴스를 초기화합니다.

ExportAttribute(String)

이 특성으로 표시된 형식이나 멤버를 지정된 계약 이름으로 내보내 ExportAttribute 클래스의 새 인스턴스를 초기화합니다.

ExportAttribute(String, Type)

지정된 형식을 지정된 계약 이름으로 내보내 ExportAttribute 클래스의 새 인스턴스를 초기화합니다.

ExportAttribute(Type)

이 특성으로 표시된 형식이나 멤버를 지정된 형식에서 파생된 계약 이름으로 내보내 ExportAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

ContractName

이 특성으로 표시된 형식이나 멤버를 내보내는 데 사용되는 계약 이름을 가져옵니다.

ContractType

이 특성이 연결된 멤버가 내보내는 계약 형식을 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보