Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.ComponentModel.Composition / src / ComponentModel / System / ComponentModel / Composition / Primitives / ComposablePartCatalog.cs
1 // -----------------------------------------------------------------------\r
2 // Copyright (c) Microsoft Corporation.  All rights reserved.\r
3 // -----------------------------------------------------------------------\r
4 using System;\r
5 using System.Collections.Generic;\r
6 using System.ComponentModel.Composition.Hosting;\r
7 using System.Diagnostics;\r
8 using System.Diagnostics.CodeAnalysis;\r
9 using System.Linq;\r
10 using System.Linq.Expressions;\r
11 using Microsoft.Internal;\r
12 \r
13 namespace System.ComponentModel.Composition.Primitives\r
14 {\r
15     /// <summary>\r
16     ///     Defines the <see langword="abstract"/> base class for composable part catalogs, which produce\r
17     ///     and return <see cref="ComposablePartDefinition"/> objects.\r
18     /// </summary>\r
19     /// <remarks>\r
20     ///     This type is thread safe.\r
21     /// </remarks>\r
22     [DebuggerTypeProxy(typeof(ComposablePartCatalogDebuggerProxy))]\r
23     public abstract class ComposablePartCatalog : IDisposable\r
24     {\r
25         private bool _isDisposed;\r
26 \r
27         /// <summary>\r
28         ///     Initializes a new instance of the <see cref="ComposablePartCatalog"/> class.\r
29         /// </summary>\r
30         protected ComposablePartCatalog()\r
31         {\r
32         }\r
33 \r
34         /// <summary>\r
35         ///     Gets the part definitions of the catalog.\r
36         /// </summary>\r
37         /// <value>\r
38         ///     A <see cref="IQueryable{T}"/> of <see cref="ComposablePartDefinition"/> objects of the \r
39         ///     <see cref="ComposablePartCatalog"/>.\r
40         /// </value>\r
41         /// <exception cref="ObjectDisposedException">\r
42         ///     The <see cref="ComposablePartCatalog"/> has been disposed of.\r
43         /// </exception>\r
44         /// <remarks>\r
45         ///     <note type="inheritinfo">\r
46         ///         Overriders of this property should never return <see langword="null"/>.\r
47         ///     </note>\r
48         /// </remarks>\r
49         public abstract IQueryable<ComposablePartDefinition> Parts \r
50         { \r
51             get; \r
52         }\r
53 \r
54         /// <summary>\r
55         ///     Returns the export definitions that match the constraint defined by the specified definition.\r
56         /// </summary>\r
57         /// <param name="definition">\r
58         ///     The <see cref="ImportDefinition"/> that defines the conditions of the \r
59         ///     <see cref="ExportDefinition"/> objects to return.\r
60         /// </param>\r
61         /// <returns>\r
62         ///     An <see cref="IEnumerable{T}"/> of <see cref="Tuple{T1, T2}"/> containing the \r
63         ///     <see cref="ExportDefinition"/> objects and their associated \r
64         ///     <see cref="ComposablePartDefinition"/> for objects that match the constraint defined \r
65         ///     by <paramref name="definition"/>.\r
66         /// </returns>\r
67         /// <exception cref="ArgumentNullException">\r
68         ///     <paramref name="definition"/> is <see langword="null"/>.\r
69         /// </exception>\r
70         /// <exception cref="ObjectDisposedException">\r
71         ///     The <see cref="ComposablePartCatalog"/> has been disposed of.\r
72         /// </exception>\r
73         /// <remarks>\r
74         ///     <note type="inheritinfo">\r
75         ///         Overriders of this property should never return <see langword="null"/>, if no \r
76         ///         <see cref="ExportDefinition"/> match the conditions defined by \r
77         ///         <paramref name="definition"/>, return an empty <see cref="IEnumerable{T}"/>.\r
78         ///     </note>\r
79         /// </remarks>\r
80         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]\r
81         public virtual IEnumerable<Tuple<ComposablePartDefinition, ExportDefinition>> GetExports(ImportDefinition definition)\r
82         {\r
83             this.ThrowIfDisposed();\r
84 \r
85             Requires.NotNull(definition, "definition");\r
86 \r
87             var exports = new List<Tuple<ComposablePartDefinition, ExportDefinition>>();\r
88             foreach (var part in this.Parts)\r
89             {\r
90                 foreach (var export in part.ExportDefinitions)\r
91                 {\r
92                     if (definition.IsConstraintSatisfiedBy(export))\r
93                     {\r
94                         exports.Add(new Tuple<ComposablePartDefinition, ExportDefinition>(part, export));\r
95                     }\r
96                 }\r
97             }\r
98             return exports;\r
99 \r
100         }\r
101 \r
102         /// <summary>\r
103         ///     Releases the unmanaged resources used by the <see cref="ComposablePartCatalog"/> and \r
104         ///     optionally releases the managed resources.\r
105         /// </summary>\r
106         /// <param name="disposing">\r
107         ///     <see langword="true"/> to release both managed and unmanaged resources; \r
108         ///     <see langword="false"/> to release only unmanaged resources.\r
109         /// </param>\r
110         public void Dispose()\r
111         {\r
112             Dispose(true);\r
113             GC.SuppressFinalize(this);\r
114         }\r
115 \r
116         protected virtual void Dispose(bool disposing) \r
117         {\r
118             this._isDisposed = true;\r
119         }\r
120 \r
121         private void ThrowIfDisposed()\r
122         {\r
123             if (this._isDisposed)\r
124             {\r
125                 throw ExceptionBuilder.CreateObjectDisposed(this);\r
126             }\r
127         }\r
128     }\r
129 }\r