Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AssemblyNameFormatter.cs
Go to the documentation of this file.
1using System.Text;
2
3namespace System.Reflection;
4
5internal 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}
static unsafe string ToString(ReadOnlySpan< byte > bytes, Casing casing=Casing.Upper)
static void AppendQuoted(this StringBuilder sb, string s)
static string ComputeDisplayName(string name, Version version, string cultureName, byte[] pkt, AssemblyNameFlags flags=AssemblyNameFlags.None, AssemblyContentType contentType=AssemblyContentType.Default)
static Version CanonicalizeVersion(this Version version)
override string ToString()
StringBuilder Append(char value, int repeatCount)