Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RuntimeCustomAttributeData.cs
Go to the documentation of this file.
5
6namespace System.Reflection;
7
9{
11
12 private readonly RuntimeModule m_scope;
13
14 private readonly MemberInfo[] m_members;
15
17
19
21
23
25
43
45 {
46 get
47 {
48 if (m_namedArgs == null)
49 {
50 if (m_namedParams == null)
51 {
52 return null;
53 }
54 int num = 0;
55 for (int i = 0; i < m_namedParams.Length; i++)
56 {
57 if (m_namedParams[i].EncodedArgument.CustomAttributeType.EncodedType != 0)
58 {
59 num++;
60 }
61 }
63 int j = 0;
64 int num2 = 0;
65 for (; j < m_namedParams.Length; j++)
66 {
67 if (m_namedParams[j].EncodedArgument.CustomAttributeType.EncodedType != 0)
68 {
70 }
71 }
72 m_namedArgs = Array.AsReadOnly(array);
73 }
74 return m_namedArgs;
75 }
76 }
77
89
101
113
118
123
128
130 {
131 if (target.IsResource())
132 {
133 return new List<CustomAttributeData>();
134 }
135 return GetCustomAttributes(target, target.MetadataToken);
136 }
137
142
154
165
167 {
168 if (type == typeof(int))
169 {
170 return CustomAttributeEncoding.Int32;
171 }
172 if (type.IsEnum)
173 {
174 return CustomAttributeEncoding.Enum;
175 }
176 if (type == typeof(string))
177 {
178 return CustomAttributeEncoding.String;
179 }
180 if (type == typeof(Type))
181 {
182 return CustomAttributeEncoding.Type;
183 }
184 if (type == typeof(object))
185 {
186 return CustomAttributeEncoding.Object;
187 }
188 if (type.IsArray)
189 {
190 return CustomAttributeEncoding.Array;
191 }
192 if (type == typeof(char))
193 {
194 return CustomAttributeEncoding.Char;
195 }
196 if (type == typeof(bool))
197 {
198 return CustomAttributeEncoding.Boolean;
199 }
200 if (type == typeof(byte))
201 {
202 return CustomAttributeEncoding.Byte;
203 }
204 if (type == typeof(sbyte))
205 {
206 return CustomAttributeEncoding.SByte;
207 }
208 if (type == typeof(short))
209 {
210 return CustomAttributeEncoding.Int16;
211 }
212 if (type == typeof(ushort))
213 {
214 return CustomAttributeEncoding.UInt16;
215 }
216 if (type == typeof(uint))
217 {
218 return CustomAttributeEncoding.UInt32;
219 }
220 if (type == typeof(long))
221 {
222 return CustomAttributeEncoding.Int64;
223 }
224 if (type == typeof(ulong))
225 {
226 return CustomAttributeEncoding.UInt64;
227 }
228 if (type == typeof(float))
229 {
230 return CustomAttributeEncoding.Float;
231 }
232 if (type == typeof(double))
233 {
234 return CustomAttributeEncoding.Double;
235 }
236 if (type == typeof(Enum))
237 {
238 return CustomAttributeEncoding.Object;
239 }
240 if (type.IsClass)
241 {
242 return CustomAttributeEncoding.Object;
243 }
244 if (type.IsInterface)
245 {
246 return CustomAttributeEncoding.Object;
247 }
248 if (type.IsValueType)
249 {
250 return CustomAttributeEncoding.Undefined;
251 }
253 }
254
273
288
290 {
291 MetadataImport metadataImport = module.MetadataImport;
292 metadataImport.EnumCustomAttributes(targetToken, out var result);
293 if (result.Length == 0)
294 {
295 return Array.Empty<CustomAttributeRecord>();
296 }
298 for (int i = 0; i < array.Length; i++)
299 {
300 metadataImport.GetCustomAttributeProps(result[i], out array[i].tkCtor.Value, out array[i].blob);
301 }
302 return array;
303 }
304
306 {
307 for (int i = 0; i < attrs.Count; i++)
308 {
309 if (attrs[i].Constructor.DeclaringType == caType)
310 {
311 return attrs[i].ConstructorArguments[parameter];
312 }
313 }
314 return default(CustomAttributeTypedArgument);
315 }
316
317 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", Justification = "Property setters and fields which are accessed by any attribute instantiation which is present in the code linker has analyzed.As such enumerating all fields and properties may return different results after trimmingbut all those which are needed to actually have data will be there.")]
318 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "We're getting a MethodBase of a constructor that we found in the metadata. The attribute constructor won't be trimmed.")]
320 {
321 m_scope = scope;
324 {
325 Type type = scope.ResolveType(scope.MetadataImport.GetParentToken(caCtorToken), null, null);
326 m_ctor = (RuntimeConstructorInfo)scope.ResolveMethod(caCtorToken, type.GenericTypeArguments, null).MethodHandle.GetMethodInfo();
327 }
330 for (int i = 0; i < parametersNoCopy.Length; i++)
331 {
333 }
334 FieldInfo[] fields = m_ctor.DeclaringType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
335 PropertyInfo[] properties = m_ctor.DeclaringType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
336 m_namedParams = new CustomAttributeNamedParameter[properties.Length + fields.Length];
337 for (int j = 0; j < fields.Length; j++)
338 {
340 }
341 for (int k = 0; k < properties.Length; k++)
342 {
343 m_namedParams[k + fields.Length] = new CustomAttributeNamedParameter(properties[k].Name, CustomAttributeEncoding.Property, InitCustomAttributeType((RuntimeType)properties[k].PropertyType));
344 }
345 m_members = new MemberInfo[fields.Length + properties.Length];
346 fields.CopyTo(m_members, 0);
347 properties.CopyTo(m_members, fields.Length);
349 }
350
352 {
354 {
356 }
358 {
360 }
362 {
364 }
366 {
368 }
369 else
370 {
372 }
373 }
374
376 {
378 m_ctor = typeFromHandle.GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0];
380 {
382 });
384 {
385 new CustomAttributeNamedArgument(typeFromHandle.GetField("EntryPoint"), dllImport.EntryPoint),
386 new CustomAttributeNamedArgument(typeFromHandle.GetField("CharSet"), dllImport.CharSet),
387 new CustomAttributeNamedArgument(typeFromHandle.GetField("ExactSpelling"), dllImport.ExactSpelling),
388 new CustomAttributeNamedArgument(typeFromHandle.GetField("SetLastError"), dllImport.SetLastError),
389 new CustomAttributeNamedArgument(typeFromHandle.GetField("PreserveSig"), dllImport.PreserveSig),
390 new CustomAttributeNamedArgument(typeFromHandle.GetField("CallingConvention"), dllImport.CallingConvention),
391 new CustomAttributeNamedArgument(typeFromHandle.GetField("BestFitMapping"), dllImport.BestFitMapping),
392 new CustomAttributeNamedArgument(typeFromHandle.GetField("ThrowOnUnmappableChar"), dllImport.ThrowOnUnmappableChar)
393 });
394 }
395
397 {
398 m_ctor = typeof(FieldOffsetAttribute).GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0];
400 {
402 });
404 }
405
407 {
409 m_ctor = typeFromHandle.GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0];
411 {
413 });
414 int num = 3;
415 if (marshalAs.MarshalType != null)
416 {
417 num++;
418 }
419 if ((object)marshalAs.MarshalTypeRef != null)
420 {
421 num++;
422 }
423 if (marshalAs.MarshalCookie != null)
424 {
425 num++;
426 }
427 num++;
428 num++;
429 if ((object)marshalAs.SafeArrayUserDefinedSubType != null)
430 {
431 num++;
432 }
434 num = 0;
435 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("ArraySubType"), marshalAs.ArraySubType);
436 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("SizeParamIndex"), marshalAs.SizeParamIndex);
437 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("SizeConst"), marshalAs.SizeConst);
438 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("IidParameterIndex"), marshalAs.IidParameterIndex);
439 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("SafeArraySubType"), marshalAs.SafeArraySubType);
440 if (marshalAs.MarshalType != null)
441 {
442 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("MarshalType"), marshalAs.MarshalType);
443 }
444 if ((object)marshalAs.MarshalTypeRef != null)
445 {
446 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("MarshalTypeRef"), marshalAs.MarshalTypeRef);
447 }
448 if (marshalAs.MarshalCookie != null)
449 {
450 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("MarshalCookie"), marshalAs.MarshalCookie);
451 }
452 if ((object)marshalAs.SafeArrayUserDefinedSubType != null)
453 {
454 array[num++] = new CustomAttributeNamedArgument(typeFromHandle.GetField("SafeArrayUserDefinedSubType"), marshalAs.SafeArrayUserDefinedSubType);
455 }
456 m_namedArgs = Array.AsReadOnly(array);
457 }
458
460 {
462 Type[] types = new Type[1] { typeof(Type) };
463 m_ctor = typeFromHandle.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, types, null);
465 {
467 });
469 m_namedArgs = Array.AsReadOnly(array);
470 }
471
472 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", Justification = "The pca object had to be created by the single ctor on the Type. So the ctor couldn't have been trimmed.")]
473 private void Init(object pca)
474 {
475 Type type = pca.GetType();
476 m_ctor = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0];
479 }
480}
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
static Type GetUnderlyingType(Type enumType)
Definition Enum.cs:309
virtual ParameterInfo[] GetParametersNoCopy()
static void GetCustomAttributes(RuntimeType type, RuntimeType caType, ref RuntimeType.ListBuilder< Attribute > pcas)
static int GetToken(RuntimeAssembly assembly)
static IList< CustomAttributeData > GetCombinedList(IList< CustomAttributeData > customAttributes, ref RuntimeType.ListBuilder< Attribute > pseudoAttributes)
void Init(TypeForwardedToAttribute forwardedTo)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeEventInfo target)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeParameterInfo target)
static IList< CustomAttributeData > GetCustomAttributes(RuntimeModule module, int tkTarget)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeFieldInfo target)
static CustomAttributeRecord[] GetCustomAttributeRecords(RuntimeModule module, int targetToken)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeModule target)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeType target)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeConstructorInfo target)
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeAssembly target)
static CustomAttributeEncoding TypeToCustomAttributeEncoding(RuntimeType type)
IList< CustomAttributeTypedArgument > m_typedCtorArgs
RuntimeCustomAttributeData(RuntimeModule scope, MetadataToken caCtorToken, in ConstArray blob)
override IList< CustomAttributeTypedArgument > ConstructorArguments
static CustomAttributeType InitCustomAttributeType(RuntimeType parameterType)
readonly CustomAttributeNamedParameter[] m_namedParams
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimePropertyInfo target)
override IList< CustomAttributeNamedArgument > NamedArguments
static CustomAttributeTypedArgument Filter(IList< CustomAttributeData > attrs, Type caType, int parameter)
IList< CustomAttributeNamedArgument > m_namedArgs
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeMethodInfo target)
readonly CustomAttributeCtorParameter[] m_ctorParams
unsafe override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
static bool IsResource(RuntimeModule module)
override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
override int MetadataToken
RuntimeModule GetRuntimeModule()
static MethodBase GetMethodBase(RuntimeModule scope, int typeMetadataToken)
static string Argument_InvalidKindOfTypeForCA
Definition SR.cs:700
Definition SR.cs:7
FieldInfo[] GetFields()
Definition Type.cs:616
PropertyInfo[] GetProperties()
Definition Type.cs:877
virtual bool IsGenericType
Definition Type.cs:111
static void ParseAttributeArguments(IntPtr pCa, int cCa, ref CustomAttributeCtorParameter[] CustomAttributeCtorParameters, ref CustomAttributeNamedParameter[] CustomAttributeTypedArgument, RuntimeAssembly assembly)