Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AssemblyNameFormatter.cs
Go to the documentation of this file.
1
using
System.Text
;
2
3
namespace
System.Reflection
;
4
5
internal
static
class
AssemblyNameFormatter
6
{
7
public
static
string
ComputeDisplayName
(
string
name,
Version
version,
string
cultureName,
byte
[] pkt,
AssemblyNameFlags
flags =
AssemblyNameFlags
.None,
AssemblyContentType
contentType =
AssemblyContentType
.Default)
8
{
9
StringBuilder
stringBuilder =
new
StringBuilder
();
10
stringBuilder.AppendQuoted(name);
11
if
(version !=
null
)
12
{
13
Version
version2 = version.CanonicalizeVersion();
14
if
(version2.
Major
!= 65535)
15
{
16
stringBuilder.
Append
(
", Version="
);
17
stringBuilder.
Append
(version2.
Major
);
18
if
(version2.
Minor
!= 65535)
19
{
20
stringBuilder.
Append
(
'.'
);
21
stringBuilder.
Append
(version2.
Minor
);
22
if
(version2.
Build
!= 65535)
23
{
24
stringBuilder.
Append
(
'.'
);
25
stringBuilder.
Append
(version2.
Build
);
26
if
(version2.
Revision
!= 65535)
27
{
28
stringBuilder.
Append
(
'.'
);
29
stringBuilder.
Append
(version2.
Revision
);
30
}
31
}
32
}
33
}
34
}
35
if
(cultureName !=
null
)
36
{
37
if
(cultureName.Length == 0)
38
{
39
cultureName =
"neutral"
;
40
}
41
stringBuilder.
Append
(
", Culture="
);
42
stringBuilder.AppendQuoted(cultureName);
43
}
44
if
(pkt !=
null
)
45
{
46
if
(pkt.Length > 8)
47
{
48
throw
new
ArgumentException
();
49
}
50
stringBuilder.
Append
(
", PublicKeyToken="
);
51
if
(pkt.Length == 0)
52
{
53
stringBuilder.
Append
(
"null"
);
54
}
55
else
56
{
57
stringBuilder.
Append
(
HexConverter
.
ToString
(pkt,
HexConverter
.
Casing
.Lower));
58
}
59
}
60
if
((flags &
AssemblyNameFlags
.Retargetable) != 0)
61
{
62
stringBuilder.
Append
(
", Retargetable=Yes"
);
63
}
64
if
(contentType ==
AssemblyContentType
.WindowsRuntime)
65
{
66
stringBuilder.
Append
(
", ContentType=WindowsRuntime"
);
67
}
68
return
stringBuilder.
ToString
();
69
}
70
71
private
static
void
AppendQuoted
(
this
StringBuilder
sb,
string
s
)
72
{
73
bool
flag =
false
;
74
if
(
s
!=
s
.Trim() ||
s
.Contains(
'"'
) ||
s
.Contains(
'\''
))
75
{
76
flag =
true
;
77
}
78
if
(flag)
79
{
80
sb.
Append
(
'"'
);
81
}
82
for
(
int
i = 0; i <
s
.Length; i++)
83
{
84
switch
(
s
[i])
85
{
86
case
'"'
:
87
case
'\''
:
88
case
','
:
89
case
'='
:
90
case
'\\'
:
91
sb.
Append
(
'\\'
);
92
break
;
93
case
'\t'
:
94
sb.
Append
(
"\\t"
);
95
continue
;
96
case
'\r'
:
97
sb.
Append
(
"\\r"
);
98
continue
;
99
case
'\n'
:
100
sb.
Append
(
"\\n"
);
101
continue
;
102
}
103
sb.
Append
(
s
[i]);
104
}
105
if
(flag)
106
{
107
sb.
Append
(
'"'
);
108
}
109
}
110
111
private
static
Version
CanonicalizeVersion
(
this
Version
version)
112
{
113
ushort num = (ushort)version.
Major
;
114
ushort num2 = (ushort)version.
Minor
;
115
ushort num3 = (ushort)version.
Build
;
116
ushort num4 = (ushort)version.
Revision
;
117
if
(num == version.
Major
&& num2 == version.
Minor
&& num3 == version.
Build
&& num4 == version.
Revision
)
118
{
119
return
version;
120
}
121
return
new
Version
(num, num2, num3, num4);
122
}
123
}
System.ArgumentException
Definition
ArgumentException.cs:9
System.HexConverter.Casing
Casing
Definition
HexConverter.cs:8
System.HexConverter.ToString
static unsafe string ToString(ReadOnlySpan< byte > bytes, Casing casing=Casing.Upper)
Definition
HexConverter.cs:30
System.HexConverter
Definition
HexConverter.cs:6
System.Reflection.AssemblyNameFormatter.AppendQuoted
static void AppendQuoted(this StringBuilder sb, string s)
Definition
AssemblyNameFormatter.cs:71
System.Reflection.AssemblyNameFormatter.ComputeDisplayName
static string ComputeDisplayName(string name, Version version, string cultureName, byte[] pkt, AssemblyNameFlags flags=AssemblyNameFlags.None, AssemblyContentType contentType=AssemblyContentType.Default)
Definition
AssemblyNameFormatter.cs:7
System.Reflection.AssemblyNameFormatter.CanonicalizeVersion
static Version CanonicalizeVersion(this Version version)
Definition
AssemblyNameFormatter.cs:111
System.Reflection.AssemblyNameFormatter
Definition
AssemblyNameFormatter.cs:6
System.Text.StringBuilder.ToString
override string ToString()
Definition
StringBuilder.cs:679
System.Text.StringBuilder.Append
StringBuilder Append(char value, int repeatCount)
Definition
StringBuilder.cs:744
System.Text.StringBuilder
Definition
StringBuilder.cs:14
System.Version.Build
int Build
Definition
Version.cs:23
System.Version.Minor
int Minor
Definition
Version.cs:21
System.Version.Revision
int Revision
Definition
Version.cs:25
System.Version.Major
int Major
Definition
Version.cs:19
System.Version
Definition
Version.cs:10
System.Reflection.AssemblyContentType
AssemblyContentType
Definition
AssemblyContentType.cs:4
System.Reflection.AssemblyNameFlags
AssemblyNameFlags
Definition
AssemblyNameFlags.cs:5
System.Reflection
Definition
ICustomTypeProvider.cs:1
System.Text
Definition
ConsoleEncoding.cs:1
System.ExceptionArgument.s
@ s
source
System.Private.CoreLib
System.Reflection
AssemblyNameFormatter.cs
Generated by
1.10.0