/
ReflectionTypeLoadException.cs
75 lines (62 loc) · 2.76 KB
/
ReflectionTypeLoadException.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
// 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.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
namespace System.Reflection
{
[Serializable]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public sealed class ReflectionTypeLoadException : SystemException
{
public ReflectionTypeLoadException(Type?[]? classes, Exception?[]? exceptions) :
this(classes, exceptions, null)
{
}
public ReflectionTypeLoadException(Type?[]? classes, Exception?[]? exceptions, string? message)
: base(message)
{
Types = classes ?? Type.EmptyTypes;
LoaderExceptions = exceptions ?? Array.Empty<Exception>();
HResult = HResults.COR_E_REFLECTIONTYPELOAD;
}
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
private ReflectionTypeLoadException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Types = Type.EmptyTypes;
LoaderExceptions = (Exception?[]?)info.GetValue("Exceptions", typeof(Exception[])) ?? Array.Empty<Exception?>();
}
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Types", null, typeof(Type[]));
info.AddValue("Exceptions", LoaderExceptions, typeof(Exception[]));
}
public Type?[] Types { get; }
public Exception?[] LoaderExceptions { get; }
public override string Message => CreateString(isMessage: true);
public override string ToString() => CreateString(isMessage: false);
private string CreateString(bool isMessage)
{
string baseValue = isMessage ? base.Message : base.ToString();
Exception?[] exceptions = LoaderExceptions;
if (exceptions.Length == 0)
{
return baseValue;
}
var text = new StringBuilder(baseValue);
foreach (Exception? e in exceptions)
{
if (e != null)
{
text.AppendLine().Append(isMessage ? e.Message : e.ToString());
}
}
return text.ToString();
}
}
}