Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PropertyTabAttribute.cs
Go to the documentation of this file.
3
5
6[AttributeUsage(AttributeTargets.All)]
8{
9 private Type[] _tabClasses;
10
11 private string[] _tabClassNames;
12
14 {
15 get
16 {
17 if (_tabClasses == null && _tabClassNames != null)
18 {
20 }
21 return _tabClasses;
22 }
23 }
24
25 protected string[]? TabClassNames => (string[])_tabClassNames?.Clone();
26
27 public PropertyTabScope[] TabScopes { get; private set; }
28
30 {
32 _tabClassNames = Array.Empty<string>();
33 }
34
35 public PropertyTabAttribute(Type tabClass)
36 : this(tabClass, PropertyTabScope.Component)
37 {
38 }
39
40 public PropertyTabAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName)
41 : this(tabClassName, PropertyTabScope.Component)
42 {
43 }
44
45 public PropertyTabAttribute(Type tabClass, PropertyTabScope tabScope)
46 {
47 _tabClasses = new Type[1] { tabClass };
48 if (tabScope < PropertyTabScope.Document)
49 {
51 }
52 TabScopes = new PropertyTabScope[1] { tabScope };
53 }
54
55 public PropertyTabAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName, PropertyTabScope tabScope)
56 {
57 _tabClassNames = new string[1] { tabClassName };
58 if (tabScope < PropertyTabScope.Document)
59 {
61 }
62 TabScopes = new PropertyTabScope[1] { tabScope };
63 }
64
65 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The APIs that specify _tabClassNames are either marked with DynamicallyAccessedMembers or RequiresUnreferencedCode.")]
66 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:TypeGetType", Justification = "The APIs that specify _tabClassNames are either marked with DynamicallyAccessedMembers or RequiresUnreferencedCode.")]
67 [MemberNotNull("_tabClasses")]
68 private void InitializeTabClasses()
69 {
70 _tabClasses = new Type[_tabClassNames.Length];
71 for (int i = 0; i < _tabClassNames.Length; i++)
72 {
73 int num = _tabClassNames[i].IndexOf(',');
74 string text = null;
75 string text2 = null;
76 if (num != -1)
77 {
78 text = _tabClassNames[i].AsSpan(0, num).Trim().ToString();
79 text2 = _tabClassNames[i].AsSpan(num + 1).Trim().ToString();
80 }
81 else
82 {
84 }
85 _tabClasses[i] = Type.GetType(text, throwOnError: false);
86 if (_tabClasses[i] == null)
87 {
88 if (text2 == null)
89 {
91 }
92 Assembly assembly = Assembly.Load(text2);
93 if (assembly != null)
94 {
95 _tabClasses[i] = assembly.GetType(text, throwOnError: true);
96 }
97 }
98 }
99 }
100
101 public override bool Equals([NotNullWhen(true)] object? other)
102 {
103 if (other is PropertyTabAttribute other2)
104 {
105 return Equals(other2);
106 }
107 return false;
108 }
109
111 {
112 if (other == this)
113 {
114 return true;
115 }
116 if (other.TabClasses.Length != TabClasses.Length || other.TabScopes.Length != TabScopes.Length)
117 {
118 return false;
119 }
120 for (int i = 0; i < TabClasses.Length; i++)
121 {
122 if (TabClasses[i] != other.TabClasses[i] || TabScopes[i] != other.TabScopes[i])
123 {
124 return false;
125 }
126 }
127 return true;
128 }
129
130 public override int GetHashCode()
131 {
132 return base.GetHashCode();
133 }
134
135 [RequiresUnreferencedCode("The Types referenced by tabClassNames may be trimmed.")]
136 protected void InitializeArrays(string[]? tabClassNames, PropertyTabScope[]? tabScopes)
137 {
138 InitializeArrays(tabClassNames, null, tabScopes);
139 }
140
141 protected void InitializeArrays(Type[]? tabClasses, PropertyTabScope[]? tabScopes)
142 {
143 InitializeArrays(null, tabClasses, tabScopes);
144 }
145
146 private void InitializeArrays(string[] tabClassNames, Type[] tabClasses, PropertyTabScope[] tabScopes)
147 {
148 if (tabClasses != null)
149 {
150 if (tabScopes != null && tabClasses.Length != tabScopes.Length)
151 {
153 }
154 _tabClasses = (Type[])tabClasses.Clone();
155 }
156 else if (tabClassNames != null)
157 {
158 if (tabScopes != null && tabClassNames.Length != tabScopes.Length)
159 {
161 }
162 _tabClassNames = (string[])tabClassNames.Clone();
163 _tabClasses = null;
164 }
165 else if (_tabClasses == null && _tabClassNames == null)
166 {
168 }
169 if (tabScopes != null)
170 {
171 for (int i = 0; i < tabScopes.Length; i++)
172 {
173 if (tabScopes[i] < PropertyTabScope.Document)
174 {
176 }
177 }
178 TabScopes = (PropertyTabScope[])tabScopes.Clone();
179 }
180 else
181 {
182 TabScopes = new PropertyTabScope[tabClasses.Length];
183 for (int j = 0; j < TabScopes.Length; j++)
184 {
185 TabScopes[j] = PropertyTabScope.Component;
186 }
187 }
188 }
189}
PropertyTabAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName)
override bool Equals([NotNullWhen(true)] object? other)
PropertyTabAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName, PropertyTabScope tabScope)
void InitializeArrays(string[]? tabClassNames, PropertyTabScope[]? tabScopes)
void InitializeArrays(string[] tabClassNames, Type[] tabClasses, PropertyTabScope[] tabScopes)
PropertyTabAttribute(Type tabClass, PropertyTabScope tabScope)
void InitializeArrays(Type[]? tabClasses, PropertyTabScope[]? tabScopes)
static Assembly Load(string assemblyString)
Definition Assembly.cs:157
virtual ? Type GetType(string name)
Definition Assembly.cs:305
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string PropertyTabAttributeParamsBothNull
Definition SR.cs:74
static string PropertyTabAttributeBadPropertyTabScope
Definition SR.cs:68
static string PropertyTabAttributeArrayLengthMismatch
Definition SR.cs:72
static string PropertyTabAttributeTypeLoadException
Definition SR.cs:70
Definition SR.cs:7
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408