2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System.ComponentModel.Composition / src / ComponentModel / System / ComponentModel / Composition / ExportAttribute.cs
blob6882f92a49457a30ed2e4dd567b95c3cb7fc0486
1 // -----------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // -----------------------------------------------------------------------
4 using System;
5 using System.ComponentModel.Composition.Hosting;
6 using System.Diagnostics.CodeAnalysis;
8 namespace System.ComponentModel.Composition
10 /// <summary>
11 /// Specifies that a type, property, field, or method provides a particular export.
12 /// </summary>
13 [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
14 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method,
15 AllowMultiple = true, Inherited = false)]
16 public class ExportAttribute : Attribute
18 /// <summary>
19 /// Initializes a new instance of the <see cref="ExportAttribute"/> class, exporting the
20 /// type or member marked with this attribute under the default contract name.
21 /// </summary>
22 /// <remarks>
23 /// <para>
24 /// The default contract name is the result of calling
25 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on the type of the
26 /// property or field, or the type itself, that is marked with this attribute.
27 /// </para>
28 /// <para>
29 /// The contract name is compared using a case-sensitive, non-linguistic comparison
30 /// using <see cref="StringComparer.Ordinal"/>.
31 /// </para>
32 /// </remarks>
33 public ExportAttribute()
34 : this((string)null, (Type)null)
38 /// <summary>
39 /// Initializes a new instance of the <see cref="ExportAttribute"/> class, exporting the
40 /// type or member marked with this attribute under a contract name derived from the
41 /// specified type.
42 /// </summary>
43 /// <param name="contractType">
44 /// A <see cref="Type"/> of which to derive the contract name to export the type or
45 /// member marked with this attribute, under; or <see langword="null"/> to use the
46 /// default contract name.
47 /// </param>
48 /// <remarks>
49 /// <para>
50 /// The contract name is the result of calling
51 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on
52 /// <paramref name="contractType"/>.
53 /// </para>
54 /// <para>
55 /// The default contract name is the result of calling
56 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on the type of the
57 /// property or field, or the type itself, that is marked with this attribute.
58 /// </para>
59 /// <para>
60 /// The contract name is compared using a case-sensitive, non-linguistic comparison
61 /// using <see cref="StringComparer.Ordinal"/>.
62 /// </para>
63 /// </remarks>
64 public ExportAttribute(Type contractType)
65 : this((string)null, contractType)
69 /// <summary>
70 /// Initializes a new instance of the <see cref="ExportAttribute"/> class, exporting the
71 /// type or member marked with this attribute under the specified contract name.
72 /// </summary>
73 /// <param name="contractName">
74 /// A <see cref="String"/> containing the contract name to export the type or member
75 /// marked with this attribute, under; or <see langword="null"/> or an empty string
76 /// ("") to use the default contract name.
77 /// </param>
78 /// <remarks>
79 /// <para>
80 /// The default contract name is the result of calling
81 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on the property or field
82 /// type, or the type itself that this is marked with this attribute.
83 /// </para>
84 /// <para>
85 /// The contract name is compared using a case-sensitive, non-linguistic comparison
86 /// using <see cref="StringComparer.Ordinal"/>.
87 /// </para>
88 /// </remarks>
89 public ExportAttribute(string contractName)
90 : this(contractName, (Type)null)
94 /// <summary>
95 /// Initializes a new instance of the <see cref="ExportAttribute"/> class, exporting the
96 /// type or member marked with this attribute under the specified contract name.
97 /// </summary>
98 /// <param name="contractName">
99 /// A <see cref="String"/> containing the contract name to export the type or member
100 /// marked with this attribute, under; or <see langword="null"/> or an empty string
101 /// ("") to use the default contract name.
102 /// </param>
103 /// <param name="contractType">
104 /// A <see cref="Type"/> of which to derive the contract name to export the type or
105 /// member marked with this attribute, under; or <see langword="null"/> to use the
106 /// default contract name.
107 /// </param>
108 /// <remarks>
109 /// <para>
110 /// The default contract name is the result of calling
111 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on the property or field
112 /// type, or the type itself that this is marked with this attribute.
113 /// </para>
114 /// <para>
115 /// The contract name is compared using a case-sensitive, non-linguistic comparison
116 /// using <see cref="StringComparer.Ordinal"/>.
117 /// </para>
118 /// </remarks>
119 public ExportAttribute(string contractName, Type contractType)
121 this.ContractName = contractName;
122 this.ContractType = contractType;
125 /// <summary>
126 /// Gets the contract name to export the type or member under.
127 /// </summary>
128 /// <value>
129 /// A <see cref="String"/> containing the contract name to export the type or member
130 /// marked with this attribute, under. The default value is an empty string ("").
131 /// </value>
132 public string ContractName { get; private set; }
134 /// <summary>
135 /// Get the contract type that is exported by the member that this attribute is attached to.
136 /// </summary>
137 /// <value>
138 /// A <see cref="Type"/> of the export that is be provided. The default value is
139 /// <see langword="null"/> which means that the type will be obtained by looking at the type on
140 /// the member that this export is attached to.
141 /// </value>
142 public Type ContractType { get; private set; }