ExportAttribute 클래스

정의

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

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

예제

다음 예제에서는 ExportAttribute가 세 개의 클래스와 일치하는 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 cases. 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 cases. 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)

적용 대상