2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System.ComponentModel.Composition / src / ComponentModel / System / ComponentModel / Composition / ImportManyAttribute.cs
blob79f706f60442bd3066a69b7fa7a4eed589d60cd0
1 // -----------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 // -----------------------------------------------------------------------
4 using System;
5 using System.ComponentModel.Composition.Hosting;
6 using System.ComponentModel.Composition.Primitives;
7 using System.Diagnostics.CodeAnalysis;
9 namespace System.ComponentModel.Composition
11 /// <summary>
12 /// Specifies that a property, field, or parameter imports a particular set of exports.
13 /// </summary>
14 [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes")]
15 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
16 AllowMultiple = false, Inherited = false)]
17 public class ImportManyAttribute : Attribute, IAttributedImport
19 /// <summary>
20 /// Initializes a new instance of the <see cref="ImportManyAttribute"/> class, importing the
21 /// set of exports with the default contract name.
22 /// </summary>
23 /// <remarks>
24 /// <para>
25 /// The default contract name is the result of calling
26 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on the element\item type of
27 /// theproperty, field, or parameter type that this is marked with this attribute.
28 /// </para>
29 /// <para>
30 /// The contract name is compared using a case-sensitive, non-linguistic comparison
31 /// using <see cref="StringComparer.Ordinal"/>.
32 /// </para>
33 /// </remarks>
34 public ImportManyAttribute()
35 : this((string)null)
39 /// <summary>
40 /// Initializes a new instance of the <see cref="ImportManyAttribute"/> class, importing the
41 /// set of exports with the contract name derived from the specified type.
42 /// </summary>
43 /// <param name="contractType">
44 /// A <see cref="Type"/> of which to derive the contract name of the exports to import, or
45 /// <see langword="null"/> to use the default contract name.
46 /// </param>
47 /// <remarks>
48 /// <para>
49 /// The contract name is the result of calling
50 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on
51 /// <paramref name="contractType"/>.
52 /// </para>
53 /// <para>
54 /// The default contract name is the result of calling
55 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on the property, field,
56 /// or parameter type that is marked with this attribute.
57 /// </para>
58 /// <para>
59 /// The contract name is compared using a case-sensitive, non-linguistic comparison
60 /// using <see cref="StringComparer.Ordinal"/>.
61 /// </para>
62 /// </remarks>
63 public ImportManyAttribute(Type contractType)
64 : this((string)null, contractType)
68 /// <summary>
69 /// Initializes a new instance of the <see cref="ImportManyAttribute"/> class, importing the
70 /// set of exports with the specified contract name.
71 /// </summary>
72 /// <param name="contractName">
73 /// A <see cref="String"/> containing the contract name of the exports to import, or
74 /// <see langword="null"/> or an empty string ("") to use the default contract name.
75 /// </param>
76 /// <remarks>
77 /// <para>
78 /// The default contract name is the result of calling
79 /// <see cref="AttributedModelServices.GetContractName(Type)"/> on the property, field,
80 /// or parameter type that is marked with this attribute.
81 /// </para>
82 /// <para>
83 /// The contract name is compared using a case-sensitive, non-linguistic comparison
84 /// using <see cref="StringComparer.Ordinal"/>.
85 /// </para>
86 /// </remarks>
87 public ImportManyAttribute(string contractName)
88 : this(contractName, (Type)null)
92 public ImportManyAttribute(string contractName, Type contractType)
94 this.ContractName = contractName;
95 this.ContractType = contractType;
98 /// <summary>
99 /// Gets the contract name of the exports to import.
100 /// </summary>
101 /// <value>
102 /// A <see cref="String"/> containing the contract name of the exports to import. The
103 /// default value is an empty string ("").
104 /// </value>
105 public string ContractName { get; private set; }
107 /// <summary>
108 /// Get the contract type of the export to import.
109 /// </summary>
110 /// <value>
111 /// A <see cref="Type"/> of the export that this import is expecting. The default value is
112 /// <see langword="null"/> which means that the type will be obtained by looking at the type on
113 /// the member that this import is attached to. If the type is <see cref="object"/> then the
114 /// importer is delaring they can accept any exported type.
115 /// </value>
116 public Type ContractType { get; private set; }
118 /// <summary>
119 /// Gets or sets a value indicating whether the property or field will be recomposed
120 /// when exports that provide the same contract that this import expects, have changed
121 /// in the container.
122 /// </summary>
123 /// <value>
124 /// <see langword="true"/> if the property or field allows for recomposition when exports
125 /// that provide the same <see cref="ContractName"/> are added or removed from the
126 /// <see cref="CompositionContainer"/>; otherwise, <see langword="false"/>.
127 /// The default value is <see langword="false"/>.
128 /// </value>
129 public bool AllowRecomposition { get; set; }
131 /// <summary>
132 /// Gets or sets a value indicating that the importer requires a specific
133 /// <see cref="CreationPolicy"/> for the exports used to satisfy this import. T
134 /// </summary>
135 /// <value>
136 /// <see cref="CreationPolicy.Any"/> - default value, used if the importer doesn't
137 /// require a specific <see cref="CreationPolicy"/>.
138 ///
139 /// <see cref="CreationPolicy.Shared"/> - Requires that all exports used should be shared
140 /// by everyone in the container.
141 ///
142 /// <see cref="CreationPolicy.NonShared"/> - Requires that all exports used should be
143 /// non-shared in a container and thus everyone gets their own instance.
144 /// </value>
145 public CreationPolicy RequiredCreationPolicy { get; set; }
147 ImportCardinality IAttributedImport.Cardinality
149 get { return ImportCardinality.ZeroOrMore; }