/
ComposablePartException.cs
177 lines (167 loc) · 8.13 KB
/
ComposablePartException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Serialization;
namespace System.ComponentModel.Composition.Primitives
{
/// <summary>
/// The exception that is thrown when an error occurs when calling methods on a
/// <see cref="ComposablePart"/>.
/// </summary>
[DebuggerTypeProxy(typeof(ComposablePartExceptionDebuggerProxy))]
[DebuggerDisplay("{Message}")]
[Serializable]
public class ComposablePartException : Exception
{
private readonly ICompositionElement? _element;
/// <summary>
/// Initializes a new instance of the <see cref="ComposablePartException"/> class.
/// </summary>
public ComposablePartException()
: this((string?)null, (ICompositionElement?)null, (Exception?)null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ComposablePartException"/> class
/// with the specified serialization data.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the serialized object data about the
/// <see cref="ComposablePartException"/>.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the
/// source or destination.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="info"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="SerializationException">
/// <paramref name="info"/> is missing a required value.
/// </exception>
/// <exception cref="InvalidCastException">
/// <paramref name="info"/> contains a value that cannot be cast to the correct type.
/// </exception>
#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
protected ComposablePartException(SerializationInfo info, StreamingContext context) : base(info, context)
{
_element = (ICompositionElement?)info.GetValue("Element", typeof(ICompositionElement));
}
/// <summary>
/// Initializes a new instance of the <see cref="ComposablePartException"/> class
/// with the specified error message.
/// </summary>
/// <param name="message">
/// A <see cref="string"/> containing a message that describes the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="Exception.Message"/> property to its default value.
/// </param>
public ComposablePartException(string? message)
: this(message, (ICompositionElement?)null, (Exception?)null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ComposablePartException"/> class
/// with the specified error message and composition element that is the cause of
/// the exception.
/// </summary>
/// <param name="message">
/// A <see cref="string"/> containing a message that describes the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="Exception.Message"/> property to its default value.
/// </param>
/// <param name="element">
/// The <see cref="ICompositionElement"/> that is the cause of the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="ComposablePartException.Element"/> property to
/// <see langword="null"/>.
/// </param>
public ComposablePartException(string? message, ICompositionElement? element)
: this(message, element, (Exception?)null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ComposablePartException"/> class
/// with the specified error message and exception that is the cause of the
/// exception.
/// </summary>
/// <param name="message">
/// A <see cref="string"/> containing a message that describes the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="Exception.Message"/> property to its default value.
/// </param>
/// <param name="innerException">
/// The <see cref="Exception"/> that is the underlying cause of the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="Exception.InnerException"/> property to <see langword="null"/>.
/// </param>
public ComposablePartException(string? message, Exception? innerException)
: this(message, (ICompositionElement?)null, innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ComposablePartException"/> class
/// with the specified error message, and composition element and exception that
/// are the cause of the exception.
/// </summary>
/// <param name="message">
/// A <see cref="string"/> containing a message that describes the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="Exception.Message"/> property to its default value.
/// </param>
/// <param name="element">
/// The <see cref="ICompositionElement"/> that is the cause of the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="ComposablePartException.Element"/> property to
/// <see langword="null"/>.
/// </param>
/// <param name="innerException">
/// The <see cref="Exception"/> that is the underlying cause of the
/// <see cref="ComposablePartException"/>; or <see langword="null"/> to set
/// the <see cref="Exception.InnerException"/> property to <see langword="null"/>.
/// </param>
public ComposablePartException(string? message, ICompositionElement? element, Exception? innerException)
: base(message, innerException)
{
_element = element;
}
/// <summary>
/// Gets the composition element that is the cause of the exception.
/// </summary>
/// <value>
/// The <see cref="ICompositionElement"/> that is the cause of the
/// <see cref="ComposablePartException"/>. The default is <see langword="null"/>.
/// </value>
public ICompositionElement? Element
{
get { return _element; }
}
/// <summary>
/// Gets the serialization data of the exception.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the serialized object data about the
/// <see cref="ComposablePartException"/>.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the
/// source or destination.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="info"/> is <see langword="null"/>.
/// </exception>
#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Element", _element.ToSerializableElement());
}
}
}