Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PseudoCustomAttribute.cs
Go to the documentation of this file.
4
5namespace System.Reflection;
6
7internal static class PseudoCustomAttribute
8{
10
36
38 {
39 bool flag = caType == typeof(object) || caType == typeof(Attribute);
40 if (flag || s_pca.Contains(caType))
41 {
42 if ((flag || caType == typeof(SerializableAttribute)) && (type.Attributes & TypeAttributes.Serializable) != 0)
43 {
45 }
46 if ((flag || caType == typeof(ComImportAttribute)) && (type.Attributes & TypeAttributes.Import) != 0)
47 {
49 }
50 }
51 }
52
54 {
55 bool flag = caType == typeof(object) || caType == typeof(Attribute);
56 if (!flag && !s_pca.Contains(caType))
57 {
58 return false;
59 }
60 if ((flag || caType == typeof(SerializableAttribute)) && (type.Attributes & TypeAttributes.Serializable) != 0)
61 {
62 return true;
63 }
64 if ((flag || caType == typeof(ComImportAttribute)) && (type.Attributes & TypeAttributes.Import) != 0)
65 {
66 return true;
67 }
68 return false;
69 }
70
72 {
73 bool flag = caType == typeof(object) || caType == typeof(Attribute);
74 if (!flag && !s_pca.Contains(caType))
75 {
76 return;
77 }
78 if (flag || caType == typeof(DllImportAttribute))
79 {
81 if (dllImportCustomAttribute != null)
82 {
84 }
85 }
86 if ((flag || caType == typeof(PreserveSigAttribute)) && (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0)
87 {
89 }
90 }
91
93 {
94 bool flag = caType == typeof(object) || caType == typeof(Attribute);
95 if (!flag && !s_pca.Contains(caType))
96 {
97 return false;
98 }
99 if ((flag || caType == typeof(DllImportAttribute)) && (method.Attributes & MethodAttributes.PinvokeImpl) != 0)
100 {
101 return true;
102 }
103 if ((flag || caType == typeof(PreserveSigAttribute)) && (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0)
104 {
105 return true;
106 }
107 return false;
108 }
109
111 {
112 bool flag = caType == typeof(object) || caType == typeof(Attribute);
113 if (!flag && !s_pca.Contains(caType))
114 {
115 return;
116 }
117 if ((flag || caType == typeof(InAttribute)) && parameter.IsIn)
118 {
119 pcas.Add(new InAttribute());
120 }
121 if ((flag || caType == typeof(OutAttribute)) && parameter.IsOut)
122 {
123 pcas.Add(new OutAttribute());
124 }
125 if ((flag || caType == typeof(OptionalAttribute)) && parameter.IsOptional)
126 {
128 }
129 if (flag || caType == typeof(MarshalAsAttribute))
130 {
132 if (marshalAsCustomAttribute != null)
133 {
135 }
136 }
137 }
138
140 {
141 bool flag = caType == typeof(object) || caType == typeof(Attribute);
142 if (!flag && !s_pca.Contains(caType))
143 {
144 return false;
145 }
146 if ((flag || caType == typeof(InAttribute)) && parameter.IsIn)
147 {
148 return true;
149 }
150 if ((flag || caType == typeof(OutAttribute)) && parameter.IsOut)
151 {
152 return true;
153 }
154 if ((flag || caType == typeof(OptionalAttribute)) && parameter.IsOptional)
155 {
156 return true;
157 }
159 {
160 return true;
161 }
162 return false;
163 }
164
166 {
167 bool flag = caType == typeof(object) || caType == typeof(Attribute);
168 if (!flag && !s_pca.Contains(caType))
169 {
170 return;
171 }
172 if (flag || caType == typeof(MarshalAsAttribute))
173 {
175 if (marshalAsCustomAttribute != null)
176 {
178 }
179 }
180 if (flag || caType == typeof(FieldOffsetAttribute))
181 {
183 if (marshalAsCustomAttribute != null)
184 {
186 }
187 }
188 if ((flag || caType == typeof(NonSerializedAttribute)) && (field.Attributes & FieldAttributes.NotSerialized) != 0)
189 {
191 }
192 }
193
195 {
196 bool flag = caType == typeof(object) || caType == typeof(Attribute);
197 if (!flag && !s_pca.Contains(caType))
198 {
199 return false;
200 }
202 {
203 return true;
204 }
206 {
207 return true;
208 }
209 if ((flag || caType == typeof(NonSerializedAttribute)) && (field.Attributes & FieldAttributes.NotSerialized) != 0)
210 {
211 return true;
212 }
213 return false;
214 }
215
217 {
218 if ((method.Attributes & MethodAttributes.PinvokeImpl) == 0)
219 {
220 return null;
221 }
222 MetadataImport metadataImport = ModuleHandle.GetMetadataImport(method.Module.ModuleHandle.GetRuntimeModule());
223 int metadataToken = method.MetadataToken;
224 metadataImport.GetPInvokeMap(metadataToken, out var attributes, out var importName, out var importDll);
225 CharSet charSet = CharSet.None;
226 switch (attributes & PInvokeAttributes.CharSetMask)
227 {
228 case PInvokeAttributes.CharSetNotSpec:
229 charSet = CharSet.None;
230 break;
231 case PInvokeAttributes.CharSetAnsi:
232 charSet = CharSet.Ansi;
233 break;
234 case PInvokeAttributes.CharSetUnicode:
235 charSet = CharSet.Unicode;
236 break;
237 case PInvokeAttributes.CharSetMask:
238 charSet = CharSet.Auto;
239 break;
240 }
242 switch (attributes & PInvokeAttributes.CallConvMask)
243 {
244 case PInvokeAttributes.CallConvWinapi:
246 break;
247 case PInvokeAttributes.CallConvCdecl:
249 break;
250 case PInvokeAttributes.CallConvStdcall:
252 break;
253 case PInvokeAttributes.CallConvThiscall:
255 break;
256 case PInvokeAttributes.CallConvFastcall:
258 break;
259 }
261 dllImportAttribute.EntryPoint = importName;
262 dllImportAttribute.CharSet = charSet;
263 dllImportAttribute.SetLastError = (attributes & PInvokeAttributes.SupportsLastError) != 0;
264 dllImportAttribute.ExactSpelling = (attributes & PInvokeAttributes.NoMangle) != 0;
265 dllImportAttribute.PreserveSig = (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;
266 dllImportAttribute.CallingConvention = callingConvention;
267 dllImportAttribute.BestFitMapping = (attributes & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
268 dllImportAttribute.ThrowOnUnmappableChar = (attributes & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
269 return dllImportAttribute;
270 }
271
273 {
274 return GetMarshalAsCustomAttribute(parameter.MetadataToken, parameter.GetRuntimeModule());
275 }
276
278 {
279 return GetMarshalAsCustomAttribute(field.MetadataToken, field.GetRuntimeModule());
280 }
281
283 {
284 ConstArray fieldMarshal = ModuleHandle.GetMetadataImport(scope).GetFieldMarshal(token);
285 if (fieldMarshal.Length == 0)
286 {
287 return null;
288 }
292 try
293 {
295 }
296 catch (TypeLoadException)
297 {
298 }
300 marshalAsAttribute.SafeArraySubType = safeArraySubType;
301 marshalAsAttribute.SafeArrayUserDefinedSubType = safeArrayUserDefinedSubType2;
302 marshalAsAttribute.IidParameterIndex = iidParamIndex;
303 marshalAsAttribute.ArraySubType = arraySubType;
304 marshalAsAttribute.SizeParamIndex = (short)sizeParamIndex;
305 marshalAsAttribute.SizeConst = sizeConst;
306 marshalAsAttribute.MarshalType = marshalType;
307 marshalAsAttribute.MarshalTypeRef = marshalTypeRef;
308 marshalAsAttribute.MarshalCookie = marshalCookie;
309 return marshalAsAttribute;
310 }
311
313 {
314 if ((object)field.DeclaringType != null && field.GetRuntimeModule().MetadataImport.GetFieldOffset(field.DeclaringType.MetadataToken, field.MetadataToken, out var offset))
315 {
316 return new FieldOffsetAttribute(offset);
317 }
318 return null;
319 }
320
322 {
323 if (type.IsInterface || type.HasElementType || type.IsGenericParameter)
324 {
325 return null;
326 }
328 switch (type.Attributes & TypeAttributes.LayoutMask)
329 {
330 case TypeAttributes.ExplicitLayout:
331 layoutKind = LayoutKind.Explicit;
332 break;
333 case TypeAttributes.NotPublic:
334 layoutKind = LayoutKind.Auto;
335 break;
336 case TypeAttributes.SequentialLayout:
337 layoutKind = LayoutKind.Sequential;
338 break;
339 }
340 CharSet charSet = CharSet.None;
341 switch (type.Attributes & TypeAttributes.StringFormatMask)
342 {
343 case TypeAttributes.NotPublic:
344 charSet = CharSet.Ansi;
345 break;
346 case TypeAttributes.AutoClass:
347 charSet = CharSet.Auto;
348 break;
349 case TypeAttributes.UnicodeClass:
350 charSet = CharSet.Unicode;
351 break;
352 }
353 type.GetRuntimeModule().MetadataImport.GetClassLayout(type.MetadataToken, out var packSize, out var classSize);
354 if (packSize == 0)
355 {
356 packSize = 8;
357 }
359 structLayoutAttribute.Pack = packSize;
360 structLayoutAttribute.Size = classSize;
361 structLayoutAttribute.CharSet = charSet;
363 }
364}
void Add(TKey key, TValue value)
static bool IsDefined(RuntimeMethodInfo method, RuntimeType caType)
static bool IsDefined(RuntimeType type, RuntimeType caType)
static bool IsDefined(RuntimeFieldInfo field, RuntimeType caType)
static MarshalAsAttribute GetMarshalAsCustomAttribute(RuntimeFieldInfo field)
static void GetCustomAttributes(RuntimeFieldInfo field, RuntimeType caType, ref RuntimeType.ListBuilder< Attribute > pcas)
static void GetCustomAttributes(RuntimeParameterInfo parameter, RuntimeType caType, ref RuntimeType.ListBuilder< Attribute > pcas)
static void GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, ref RuntimeType.ListBuilder< Attribute > pcas)
static bool IsDefined(RuntimeParameterInfo parameter, RuntimeType caType)
static FieldOffsetAttribute GetFieldOffsetCustomAttribute(RuntimeFieldInfo field)
static void GetCustomAttributes(RuntimeType type, RuntimeType caType, ref RuntimeType.ListBuilder< Attribute > pcas)
static MarshalAsAttribute GetMarshalAsCustomAttribute(int token, RuntimeModule scope)
static DllImportAttribute GetDllImportCustomAttribute(RuntimeMethodInfo method)
static MarshalAsAttribute GetMarshalAsCustomAttribute(RuntimeParameterInfo parameter)
static StructLayoutAttribute GetStructLayoutCustomAttribute(RuntimeType type)
static readonly HashSet< RuntimeType > s_pca
static HashSet< RuntimeType > CreatePseudoCustomAttributeHashSet()
static MetadataImport GetMetadataImport(RuntimeModule module)
static void GetMarshalAs(ConstArray nativeType, out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string safeArrayUserDefinedSubType, out UnmanagedType arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie, out int iidParamIndex)
static void GetTypeByNameUsingCARules(string name, QCallModule scope, ObjectHandleOnStack type)