Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono.git] / mcs / class / System.ComponentModel.Composition / src / ComponentModel / System / ComponentModel / Composition / CompositionError.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;\r
8 using System.Globalization;\r
9 using System.Security.Permissions;\r
10 using Microsoft.Internal;\r
11 \r
12 namespace System.ComponentModel.Composition\r
13 {\r
14     /// <summary>\r
15     ///     Represents an error that occurs during composition in a <see cref="CompositionContainer"/>.\r
16     /// </summary>\r
17     [Serializable]\r
18     [DebuggerTypeProxy(typeof(CompositionErrorDebuggerProxy))]\r
19     public class CompositionError : ICompositionError\r
20     {\r
21         private readonly CompositionErrorId _id;\r
22         private readonly string _description;\r
23         private readonly Exception _exception;\r
24 \r
25         private readonly ICompositionElement _element;\r
26 \r
27         /// <summary>\r
28         ///     Initializes a new instance of the <see cref="CompositionError"/> class\r
29         ///     with the specified error message.\r
30         /// </summary>\r
31         /// <param name="message">\r
32         ///     A <see cref="String"/> containing a message that describes the \r
33         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set the \r
34         ///     <see cref="Description"/> property to an empty string ("").\r
35         /// </param>\r
36         public CompositionError(string message)\r
37             : this(CompositionErrorId.Unknown, message, (ICompositionElement)null, (Exception)null)\r
38         {\r
39         }\r
40 \r
41         /// <summary>\r
42         ///     Initializes a new instance of the <see cref="CompositionError"/> class\r
43         ///     with the specified error message and composition element that is the\r
44         ///     cause of the composition error.\r
45         /// </summary>\r
46         /// <param name="element">\r
47         ///     The <see cref="ICompositionElement"/> that is the cause of the\r
48         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set\r
49         ///     the <see cref="CompositionError.Element"/> property to \r
50         ///     <see langword="null"/>.\r
51         /// </param>\r
52         /// <param name="message">\r
53         ///     A <see cref="String"/> containing a message that describes the \r
54         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set the \r
55         ///     <see cref="Description"/> property to an empty string ("").\r
56         /// </param>\r
57         public CompositionError(string message, ICompositionElement element)\r
58             : this(CompositionErrorId.Unknown, message, element, (Exception)null)\r
59         {\r
60         }\r
61 \r
62         /// <summary>\r
63         ///     Initializes a new instance of the <see cref="CompositionError"/> class \r
64         ///     with the specified error message and exception that is the cause of the  \r
65         ///     composition error.\r
66         /// </summary>\r
67         /// <param name="message">\r
68         ///     A <see cref="String"/> containing a message that describes the \r
69         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set the \r
70         ///     <see cref="Description"/> property to an empty string ("").\r
71         /// </param>\r
72         /// <param name="exception">\r
73         ///     The <see cref="Exception"/> that is the underlying cause of the \r
74         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set\r
75         ///     the <see cref="CompositionError.Exception"/> property to <see langword="null"/>.\r
76         /// </param>\r
77         public CompositionError(string message, Exception exception)\r
78             : this(CompositionErrorId.Unknown, message, (ICompositionElement)null, exception)\r
79         {\r
80         }\r
81 \r
82         /// <summary>\r
83         ///     Initializes a new instance of the <see cref="CompositionError"/> class \r
84         ///     with the specified error message, and composition element and exception that \r
85         ///     is the cause of the composition error.\r
86         /// </summary>\r
87         /// <param name="message">\r
88         ///     A <see cref="String"/> containing a message that describes the \r
89         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set the \r
90         ///     <see cref="Description"/> property to an empty string ("").\r
91         /// </param>\r
92         /// <param name="element">\r
93         ///     The <see cref="ICompositionElement"/> that is the cause of the\r
94         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set\r
95         ///     the <see cref="CompositionError.Element"/> property to \r
96         ///     <see langword="null"/>.\r
97         /// </param>\r
98         /// <param name="exception">\r
99         ///     The <see cref="Exception"/> that is the underlying cause of the \r
100         ///     <see cref="CompositionError"/>; or <see langword="null"/> to set\r
101         ///     the <see cref="CompositionError.Exception"/> property to <see langword="null"/>.\r
102         /// </param>\r
103         public CompositionError(string message, ICompositionElement element, Exception exception)\r
104             : this(CompositionErrorId.Unknown, message, element, exception)\r
105         {\r
106         }\r
107 \r
108         internal CompositionError(CompositionErrorId id, string description, ICompositionElement element, Exception exception)\r
109         {\r
110             _id = id;\r
111             _description = description ?? string.Empty;\r
112             _element = element;\r
113             _exception = exception;\r
114         }\r
115 \r
116         /// <summary>\r
117         ///     Gets the composition element that is the cause of the error.\r
118         /// </summary>\r
119         /// <value>\r
120         ///     The <see cref="ICompositionElement"/> that is the cause of the\r
121         ///     <see cref="CompositionError"/>. The default is <see langword="null"/>.\r
122         /// </value>\r
123         public ICompositionElement Element\r
124         {\r
125             get { return _element; }\r
126         }\r
127 \r
128         /// <summary>\r
129         ///     Gets the message that describes the composition error.\r
130         /// </summary>\r
131         /// <value>\r
132         ///     A <see cref="String"/> containing a message that describes the\r
133         ///     <see cref="CompositionError"/>.\r
134         /// </value>\r
135         public string Description\r
136         {\r
137             get { return _description; }\r
138         }\r
139 \r
140         /// <summary>\r
141         ///     Gets the exception that is the underlying cause of the composition error.\r
142         /// </summary>\r
143         /// <value>\r
144         ///     The <see cref="Exception"/> that is the underlying cause of the \r
145         ///     <see cref="CompositionError"/>. The default is <see langword="null"/>.\r
146         /// </value>\r
147         public Exception Exception\r
148         {\r
149             get { return _exception; }\r
150         }\r
151 \r
152         CompositionErrorId ICompositionError.Id\r
153         {\r
154             get { return _id; }\r
155         }\r
156 \r
157         Exception ICompositionError.InnerException\r
158         {\r
159             get { return Exception; }\r
160         }\r
161 \r
162         /// <summary>\r
163         ///     Returns a string representation of the composition error.\r
164         /// </summary>\r
165         /// <returns>\r
166         ///     A <see cref="String"/> containing the <see cref="Description"/> property.\r
167         /// </returns>\r
168         public override string ToString()\r
169         {\r
170             return this.Description;\r
171         }\r
172 \r
173         internal static CompositionError Create(CompositionErrorId id, string format, params object[] parameters)\r
174         {\r
175             return Create(id, (ICompositionElement)null, (Exception)null, format, parameters);\r
176         }\r
177 \r
178         internal static CompositionError Create(CompositionErrorId id, ICompositionElement element, string format, params object[] parameters)\r
179         {\r
180             return Create(id, element, (Exception)null, format, parameters);\r
181         }\r
182 \r
183         internal static CompositionError Create(CompositionErrorId id, ICompositionElement element, Exception exception, string format, params object[] parameters)\r
184         {\r
185             return new CompositionError(id, string.Format(CultureInfo.CurrentCulture, format, parameters), element, exception);\r
186         }\r
187     }\r
188 }\r