Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RuntimeModule.cs
Go to the documentation of this file.
3using System.IO;
7
8namespace System.Reflection;
9
10internal class RuntimeModule : Module
11{
13
15
17
18 private IntPtr m_pData;
19
21
23
24 public override int MDStreamVersion => ModuleHandle.GetMDStreamVersion(this);
25
27
29
30 [RequiresAssemblyFiles("Returns <Unknown> for modules with no file path")]
31 public override string FullyQualifiedName => GetFullyQualifiedName();
32
33 public override Guid ModuleVersionId
34 {
35 get
36 {
38 return mvid;
39 }
40 }
41
42 public override int MetadataToken => ModuleHandle.GetToken(this);
43
44 public override string ScopeName
45 {
46 get
47 {
48 string s = null;
49 RuntimeModule module = this;
51 return s;
52 }
53 }
54
55 [RequiresAssemblyFiles("Returns <Unknown> for modules with no file path")]
56 public override string Name
57 {
58 get
59 {
61 int num = fullyQualifiedName.LastIndexOf(Path.DirectorySeparatorChar);
62 if (num == -1)
63 {
64 return fullyQualifiedName;
65 }
66 return fullyQualifiedName.Substring(num + 1);
67 }
68 }
69
70 public override Assembly Assembly => GetRuntimeAssembly();
71
72 internal RuntimeModule()
73 {
74 throw new NotSupportedException();
75 }
76
77 [DllImport("QCall", CharSet = CharSet.Unicode)]
79
80 [DllImport("QCall", CharSet = CharSet.Unicode)]
82
83 [DllImport("QCall", CharSet = CharSet.Unicode)]
85
86 [MethodImpl(MethodImplOptions.InternalCall)]
87 private static extern RuntimeType[] GetTypes(RuntimeModule module);
88
90 {
91 return GetTypes(this);
92 }
93
94 [MethodImpl(MethodImplOptions.InternalCall)]
95 private static extern bool IsResource(RuntimeModule module);
96
98 {
99 if (genericArguments == null)
100 {
101 return null;
102 }
103 int num = genericArguments.Length;
105 for (int i = 0; i < num; i++)
106 {
108 if (type == null)
109 {
111 }
112 type = type.UnderlyingSystemType;
113 if (type == null)
114 {
116 }
117 if (!(type is RuntimeType))
118 {
120 }
121 array[i] = type.GetTypeHandleInternal();
122 }
123 return array;
124 }
125
126 [RequiresUnreferencedCode("Trimming changes metadata tokens")]
127 public override byte[] ResolveSignature(int metadataToken)
128 {
131 {
133 }
134 if (!metadataToken2.IsMemberRef && !metadataToken2.IsMethodDef && !metadataToken2.IsTypeSpec && !metadataToken2.IsSignature && !metadataToken2.IsFieldDef)
135 {
136 throw new ArgumentException(SR.Format(SR.Argument_InvalidToken, metadataToken2, this), "metadataToken");
137 }
139 byte[] array = new byte[constArray.Length];
140 for (int i = 0; i < constArray.Length; i++)
141 {
142 array[i] = constArray[i];
143 }
144 return array;
145 }
146
147 [RequiresUnreferencedCode("Trimming changes metadata tokens")]
149 {
150 try
151 {
153 if (!metadataToken2.IsMethodDef && !metadataToken2.IsMethodSpec)
154 {
155 if (!metadataToken2.IsMemberRef)
156 {
157 throw new ArgumentException(SR.Format(SR.Argument_ResolveMethod, metadataToken2, this), "metadataToken");
158 }
160 {
161 throw new ArgumentException(SR.Format(SR.Argument_ResolveMethod, metadataToken2, this), "metadataToken");
162 }
163 }
166 if (genericTypeArguments != null && genericTypeArguments.Length != 0)
167 {
169 }
170 if (genericMethodArguments != null && genericMethodArguments.Length != 0)
171 {
173 }
176 if (type.IsGenericType || type.IsArray)
177 {
179 if (metadataToken2.IsMethodSpec)
180 {
182 }
184 }
186 }
188 {
190 }
191 }
192
193 [RequiresUnreferencedCode("Trimming changes metadata tokens")]
195 {
198 {
200 }
204 type.GetFields();
205 try
206 {
207 return type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
208 }
209 catch
210 {
211 throw new ArgumentException(SR.Format(SR.Argument_ResolveField, metadataToken2, this), "metadataToken");
212 }
213 }
214
215 [RequiresUnreferencedCode("Trimming changes metadata tokens")]
217 {
218 try
219 {
222 {
224 }
227 if (genericTypeArguments != null && genericTypeArguments.Length != 0)
228 {
230 }
231 if (genericMethodArguments != null && genericMethodArguments.Length != 0)
232 {
234 }
236 if (!metadataToken2.IsFieldDef)
237 {
238 if (!metadataToken2.IsMemberRef)
239 {
240 throw new ArgumentException(SR.Format(SR.Argument_ResolveField, metadataToken2, this), "metadataToken");
241 }
243 {
244 throw new ArgumentException(SR.Format(SR.Argument_ResolveField, metadataToken2, this), "metadataToken");
245 }
246 }
249 if (runtimeType.IsGenericType || runtimeType.IsArray)
250 {
251 int parentToken = ModuleHandle.GetMetadataImport(this).GetParentToken(metadataToken);
253 }
255 }
257 {
259 }
261 {
263 }
264 }
265
266 [RequiresUnreferencedCode("Trimming changes metadata tokens")]
297
298 [RequiresUnreferencedCode("Trimming changes metadata tokens")]
300 {
302 if (metadataToken2.IsProperty)
303 {
305 }
306 if (metadataToken2.IsEvent)
307 {
309 }
310 if (metadataToken2.IsMethodSpec || metadataToken2.IsMethodDef)
311 {
313 }
314 if (metadataToken2.IsFieldDef)
315 {
317 }
318 if (metadataToken2.IsTypeRef || metadataToken2.IsTypeDef || metadataToken2.IsTypeSpec)
319 {
321 }
322 if (metadataToken2.IsMemberRef)
323 {
325 {
327 }
329 {
331 }
333 }
334 throw new ArgumentException(SR.Format(SR.Argument_ResolveMember, metadataToken2, this), "metadataToken");
335 }
336
337 [RequiresUnreferencedCode("Trimming changes metadata tokens")]
338 public override string ResolveString(int metadataToken)
339 {
341 if (!metadataToken2.IsString)
342 {
344 }
346 {
348 }
350 if (userString == null)
351 {
353 }
354 return userString;
355 }
356
361
362 [RequiresUnreferencedCode("Methods might be removed because Module methods can't currently be annotated for dynamic access.")]
367
368 [RequiresUnreferencedCode("Methods might be removed because Module methods can't currently be annotated for dynamic access.")]
370 {
371 if (RuntimeType == null)
372 {
373 return null;
374 }
375 if (types == null)
376 {
377 return RuntimeType.GetMethod(name, bindingAttr);
378 }
380 }
381
382 public override object[] GetCustomAttributes(bool inherit)
383 {
385 }
386
387 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
388 {
389 if (attributeType == null)
390 {
391 throw new ArgumentNullException("attributeType");
392 }
394 if (runtimeType == null)
395 {
396 throw new ArgumentException(SR.Arg_MustBeType, "attributeType");
397 }
399 }
400
401 public override bool IsDefined(Type attributeType, bool inherit)
402 {
403 if (attributeType == null)
404 {
405 throw new ArgumentNullException("attributeType");
406 }
408 if (runtimeType == null)
409 {
410 throw new ArgumentException(SR.Arg_MustBeType, "attributeType");
411 }
413 }
414
419
421 {
423 }
424
425 [RequiresUnreferencedCode("Types might be removed")]
426 public override Type GetType(string className, bool throwOnError, bool ignoreCase)
427 {
428 if (className == null)
429 {
430 throw new ArgumentNullException("className");
431 }
432 RuntimeType o = null;
433 object o2 = null;
434 RuntimeModule module = this;
436 GC.KeepAlive(o2);
437 return o;
438 }
439
440 [RequiresAssemblyFiles("Returns <Unknown> for modules with no file path")]
441 internal string GetFullyQualifiedName()
442 {
443 string s = null;
444 RuntimeModule module = this;
446 return s;
447 }
448
449 [RequiresUnreferencedCode("Types might be removed")]
450 public override Type[] GetTypes()
451 {
452 return GetTypes(this);
453 }
454
455 public override bool IsResource()
456 {
457 return IsResource(this);
458 }
459
460 [RequiresUnreferencedCode("Fields might be removed")]
462 {
463 if (RuntimeType == null)
464 {
465 return Array.Empty<FieldInfo>();
466 }
468 }
469
470 [RequiresUnreferencedCode("Fields might be removed")]
471 public override FieldInfo GetField(string name, BindingFlags bindingAttr)
472 {
473 if (name == null)
474 {
475 throw new ArgumentNullException("name");
476 }
477 if (RuntimeType == null)
478 {
479 return null;
480 }
481 return RuntimeType.GetField(name, bindingAttr);
482 }
483
484 [RequiresUnreferencedCode("Methods might be removed")]
486 {
487 if (RuntimeType == null)
488 {
489 return Array.Empty<MethodInfo>();
490 }
492 }
493
495 {
496 return m_runtimeAssembly;
497 }
498
500 {
501 return new ModuleHandle(this);
502 }
503
505 {
506 return m_pData;
507 }
508}
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
static readonly char DirectorySeparatorChar
Definition Path.cs:71
static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
static bool IsDefined(RuntimeType type, RuntimeType caType, bool inherit)
ModuleHandle ModuleHandle
Definition Module.cs:64
static IList< CustomAttributeData > GetCustomAttributesInternal(RuntimeType target)
unsafe override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
FieldInfo ResolveLiteralField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
override ModuleHandle GetModuleHandleImpl()
static bool IsResource(RuntimeModule module)
static void GetType(QCallModule module, string className, bool throwOnError, bool ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
override FieldInfo[] GetFields(BindingFlags bindingFlags)
unsafe override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
override IList< CustomAttributeData > GetCustomAttributesData()
override string ResolveString(int metadataToken)
override object[] GetCustomAttributes(bool inherit)
RuntimeAssembly GetRuntimeAssembly()
static void GetFullyQualifiedName(QCallModule module, StringHandleOnStack retString)
unsafe override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
override MethodInfo[] GetMethods(BindingFlags bindingFlags)
static void GetScopeName(QCallModule module, StringHandleOnStack retString)
MethodInfo GetMethodInternal(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
override void GetObjectData(SerializationInfo info, StreamingContext context)
override FieldInfo GetField(string name, BindingFlags bindingAttr)
override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
static RuntimeType[] GetTypes(RuntimeModule module)
override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
static RuntimeTypeHandle[] ConvertToTypeHandleArray(Type[] genericArguments)
override byte[] ResolveSignature(int metadataToken)
override bool IsDefined(Type attributeType, bool inherit)
override object[] GetCustomAttributes(Type attributeType, bool inherit)
override Type GetType(string className, bool throwOnError, bool ignoreCase)
override FieldInfo[] GetFields(BindingFlags bindingAttr)
override MethodInfo[] GetMethods(BindingFlags bindingAttr)
static FieldInfo GetFieldInfo(IRuntimeFieldInfo fieldHandle)
override FieldInfo GetField(string name, BindingFlags bindingAttr)
static MethodBase GetMethodBase(RuntimeModule scope, int typeMetadataToken)
static string Argument_BadImageFormatExceptionResolve
Definition SR.cs:490
static string Argument_ResolveField
Definition SR.cs:850
static string Arg_MustBeType
Definition SR.cs:302
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_ResolveModuleType
Definition SR.cs:860
static string Argument_ResolveMethod
Definition SR.cs:856
static string Argument_InvalidToken
Definition SR.cs:744
static string Argument_InvalidGenericInstArray
Definition SR.cs:690
static string Argument_ResolveMember
Definition SR.cs:854
static string InvalidOperation_PropertyInfoNotAvailable
Definition SR.cs:1502
static string Argument_ResolveType
Definition SR.cs:864
static string Argument_ResolveString
Definition SR.cs:862
static string InvalidOperation_EventInfoNotAvailable
Definition SR.cs:1446
Definition SR.cs:7
MethodInfo? GetMethod(string name)
Definition Type.cs:675
unsafe override string ToString()
static void GetModuleType(QCallModule handle, ObjectHandleOnStack type)
static unsafe void GetPEKind(QCallModule handle, int *peKind, int *machine)
static int GetToken(RuntimeModule module)
static MetadataImport GetMetadataImport(RuntimeModule module)
static int GetMDStreamVersion(RuntimeModule module)
RuntimeMethodHandle ResolveMethodHandle(int methodToken)
unsafe string GetUserString(int mdToken)
ConstArray GetSignatureFromToken(int token)
ConstArray GetMemberRefProps(int memberTokenRef)
unsafe MdUtf8String GetName(int mdToken)
static RuntimeType GetApproxDeclaringType(RuntimeFieldHandleInternal field)
IRuntimeMethodInfo GetMethodInfo()
static RuntimeType GetDeclaringType(RuntimeMethodHandleInternal method)