/
HostProtectionException.cs
99 lines (85 loc) · 4.02 KB
/
HostProtectionException.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
// 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.Serialization;
using System.Security.Permissions;
using System.Text;
namespace System.Security
{
#if NETCOREAPP
[Obsolete(Obsoletions.CodeAccessSecurityMessage, DiagnosticId = Obsoletions.CodeAccessSecurityDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public partial class HostProtectionException : SystemException
{
private const string ProtectedResourcesName = "ProtectedResources";
private const string DemandedResourcesName = "DemandedResources";
private const int E_HostProtection = -2146232768;
public HostProtectionException() : base()
{
HResult = E_HostProtection;
ProtectedResources = HostProtectionResource.None;
DemandedResources = HostProtectionResource.None;
}
public HostProtectionException(string message) : base(message)
{
HResult = E_HostProtection;
ProtectedResources = HostProtectionResource.None;
DemandedResources = HostProtectionResource.None;
}
public HostProtectionException(string message, Exception e) : base(message, e)
{
HResult = E_HostProtection;
ProtectedResources = HostProtectionResource.None;
DemandedResources = HostProtectionResource.None;
}
public HostProtectionException(string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources)
: base(message)
{
HResult = E_HostProtection;
ProtectedResources = protectedResources;
DemandedResources = demandedResources;
}
#if NET8_0_OR_GREATER
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
protected HostProtectionException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
ProtectedResources = (HostProtectionResource)info.GetValue(ProtectedResourcesName, typeof(HostProtectionResource));
DemandedResources = (HostProtectionResource)info.GetValue(DemandedResourcesName, typeof(HostProtectionResource));
}
public HostProtectionResource DemandedResources { get; }
public HostProtectionResource ProtectedResources { get; }
private static void AppendResourceString(string resourceString, object attr, StringBuilder sb)
{
if (attr == null)
return;
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
sb.Append(resourceString);
sb.Append(Environment.NewLine);
sb.Append(attr);
}
public override string ToString()
{
var sb = new StringBuilder();
sb.Append(base.ToString());
AppendResourceString(SR.HostProtection_ProtectedResources, ProtectedResources, sb);
AppendResourceString(SR.HostProtection_DemandedResources, DemandedResources, sb);
return sb.ToString();
}
#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(ProtectedResourcesName, ProtectedResources, typeof(HostProtectionResource));
info.AddValue(DemandedResourcesName, DemandedResources, typeof(HostProtectionResource));
}
}
}