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