Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Assembly.cs
Go to the documentation of this file.
5using System.IO;
10using System.Security;
12
13namespace System.Reflection;
14
16{
18
19 private static readonly List<string> s_loadFromAssemblyList = new List<string>();
20
21 private static bool s_loadFromHandlerSet;
22
23 private static int s_cachedSerializationSwitch;
24
25 private static bool s_forceNullEntryPoint;
26
28 {
29 [RequiresUnreferencedCode("Types might be removed")]
30 get
31 {
32 Type[] types = GetTypes();
33 TypeInfo[] array = new TypeInfo[types.Length];
34 for (int i = 0; i < types.Length; i++)
35 {
36 TypeInfo typeInfo = types[i].GetTypeInfo();
37 if (typeInfo == null)
38 {
40 }
41 array[i] = typeInfo;
42 }
43 return array;
44 }
45 }
46
48 {
49 [RequiresUnreferencedCode("Types might be removed")]
50 get
51 {
52 return GetExportedTypes();
53 }
54 }
55
56 [RequiresAssemblyFiles("This member throws an exception for assemblies embedded in a single-file app")]
57 public virtual string? CodeBase
58 {
59 get
60 {
62 }
63 }
64
65 public virtual MethodInfo? EntryPoint
66 {
67 get
68 {
70 }
71 }
72
73 public virtual string? FullName
74 {
75 get
76 {
78 }
79 }
80
81 public virtual string ImageRuntimeVersion
82 {
83 get
84 {
86 }
87 }
88
89 public virtual bool IsDynamic => false;
90
91 public virtual string Location
92 {
93 get
94 {
96 }
97 }
98
99 public virtual bool ReflectionOnly
100 {
101 get
102 {
104 }
105 }
106
107 public virtual bool IsCollectible => true;
108
109 public bool IsFullyTrusted => true;
110
112
113 [RequiresAssemblyFiles("This member throws an exception for assemblies embedded in a single-file app")]
115
116 public virtual Module ManifestModule
117 {
118 get
119 {
121 }
122 }
123
125
126 [Obsolete("The Global Assembly Cache is not supported.", DiagnosticId = "SYSLIB0005", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
127 public virtual bool GlobalAssemblyCache
128 {
129 get
130 {
132 }
133 }
134
135 public virtual long HostContext
136 {
137 get
138 {
140 }
141 }
142
144
146 {
147 add
148 {
150 }
151 remove
152 {
154 }
155 }
156
162
163 [Obsolete("Assembly.LoadWithPartialName has been deprecated. Use Assembly.Load() instead.")]
165 {
166 if (partialName == null)
167 {
168 throw new ArgumentNullException("partialName");
169 }
170 if (partialName.Length == 0 || partialName[0] == '\0')
171 {
172 throw new ArgumentException(SR.Format_StringZeroLength, "partialName");
173 }
174 try
175 {
176 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
178 }
180 {
181 return null;
182 }
183 }
184
186 {
187 if (assemblyRef == null)
188 {
189 throw new ArgumentNullException("assemblyRef");
190 }
191 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
193 }
194
195 [DllImport("QCall", CharSet = CharSet.Unicode)]
197
204
206 {
207 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
209 }
210
212 {
213 StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller;
215 }
216
217 [DllImport("QCall", CharSet = CharSet.Unicode)]
219
221 {
222 RuntimeAssembly o = null;
224 return o;
225 }
226
227 [MethodImpl(MethodImplOptions.AggressiveInlining)]
228 internal bool IsRuntimeImplemented()
229 {
230 return this is RuntimeAssembly;
231 }
232
233 [MethodImpl(MethodImplOptions.InternalCall)]
234 internal static extern uint GetAssemblyCount();
235
236 [RequiresUnreferencedCode("Types might be removed")]
237 public virtual Type[] GetTypes()
238 {
240 if (modules.Length == 1)
241 {
242 return modules[0].GetTypes();
243 }
244 int num = 0;
245 Type[][] array = new Type[modules.Length][];
246 for (int i = 0; i < array.Length; i++)
247 {
248 array[i] = modules[i].GetTypes();
249 num += array[i].Length;
250 }
251 int num2 = 0;
252 Type[] array2 = new Type[num];
253 for (int j = 0; j < array.Length; j++)
254 {
255 int num3 = array[j].Length;
256 Array.Copy(array[j], 0, array2, num2, num3);
257 num2 += num3;
258 }
259 return array2;
260 }
261
262 [RequiresUnreferencedCode("Types might be removed")]
263 public virtual Type[] GetExportedTypes()
264 {
266 }
267
268 [RequiresUnreferencedCode("Types might be removed")]
269 public virtual Type[] GetForwardedTypes()
270 {
272 }
273
278
279 public virtual string[] GetManifestResourceNames()
280 {
282 }
283
284 public virtual Stream? GetManifestResourceStream(string name)
285 {
287 }
288
289 public virtual Stream? GetManifestResourceStream(Type type, string name)
290 {
292 }
293
294 public virtual AssemblyName GetName()
295 {
296 return GetName(copiedName: false);
297 }
298
299 public virtual AssemblyName GetName(bool copiedName)
300 {
302 }
303
304 [RequiresUnreferencedCode("Types might be removed")]
305 public virtual Type? GetType(string name)
306 {
307 return GetType(name, throwOnError: false, ignoreCase: false);
308 }
309
310 [RequiresUnreferencedCode("Types might be removed")]
311 public virtual Type? GetType(string name, bool throwOnError)
312 {
313 return GetType(name, throwOnError, ignoreCase: false);
314 }
315
316 [RequiresUnreferencedCode("Types might be removed")]
317 public virtual Type? GetType(string name, bool throwOnError, bool ignoreCase)
318 {
320 }
321
322 public virtual bool IsDefined(Type attributeType, bool inherit)
323 {
325 }
326
331
332 public virtual object[] GetCustomAttributes(bool inherit)
333 {
335 }
336
337 public virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
338 {
340 }
341
342 [RequiresUnreferencedCode("Assembly.CreateInstance is not supported with trimming. Use Type.GetType instead.")]
343 public object? CreateInstance(string typeName)
344 {
345 return CreateInstance(typeName, ignoreCase: false, BindingFlags.Instance | BindingFlags.Public, null, null, null, null);
346 }
347
348 [RequiresUnreferencedCode("Assembly.CreateInstance is not supported with trimming. Use Type.GetType instead.")]
349 public object? CreateInstance(string typeName, bool ignoreCase)
350 {
351 return CreateInstance(typeName, ignoreCase, BindingFlags.Instance | BindingFlags.Public, null, null, null, null);
352 }
353
354 [RequiresUnreferencedCode("Assembly.CreateInstance is not supported with trimming. Use Type.GetType instead.")]
355 public virtual object? CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object[]? args, CultureInfo? culture, object[]? activationAttributes)
356 {
357 Type type = GetType(typeName, throwOnError: false, ignoreCase);
358 if (type == null)
359 {
360 return null;
361 }
363 }
364
365 public virtual Module? GetModule(string name)
366 {
368 }
369
371 {
372 return GetModules(getResourceModules: false);
373 }
374
375 public virtual Module[] GetModules(bool getResourceModules)
376 {
378 }
379
381 {
383 }
384
386 {
388 }
389
390 [RequiresUnreferencedCode("Assembly references might be removed")]
392 {
394 }
395
400
402 {
404 }
405
406 [RequiresAssemblyFiles("This member throws an exception for assemblies embedded in a single-file app")]
407 public virtual FileStream? GetFile(string name)
408 {
410 }
411
412 [RequiresAssemblyFiles("This member throws an exception for assemblies embedded in a single-file app")]
413 public virtual FileStream[] GetFiles()
414 {
415 return GetFiles(getResourceModules: false);
416 }
417
418 [RequiresAssemblyFiles("This member throws an exception for assemblies embedded in a single-file app")]
420 {
422 }
423
425 {
427 }
428
429 public override string ToString()
430 {
431 return FullName ?? base.ToString();
432 }
433
434 public override bool Equals(object? o)
435 {
436 return base.Equals(o);
437 }
438
439 public override int GetHashCode()
440 {
441 return base.GetHashCode();
442 }
443
444 [MethodImpl(MethodImplOptions.AggressiveInlining)]
445 public static bool operator ==(Assembly? left, Assembly? right)
446 {
447 if ((object)right == null)
448 {
449 if ((object)left != null)
450 {
451 return false;
452 }
453 return true;
454 }
455 if ((object)left == right)
456 {
457 return true;
458 }
459 return left?.Equals(right) ?? false;
460 }
461
462 public static bool operator !=(Assembly? left, Assembly? right)
463 {
464 return !(left == right);
465 }
466
467 public static string CreateQualifiedName(string? assemblyName, string? typeName)
468 {
469 return typeName + ", " + assemblyName;
470 }
471
473 {
474 if (type == null)
475 {
476 throw new ArgumentNullException("type");
477 }
478 Module module = type.Module;
479 if (module == null)
480 {
481 return null;
482 }
483 return module.Assembly;
484 }
485
486 public static Assembly? GetEntryAssembly()
487 {
489 {
490 return null;
491 }
493 }
494
495 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
496 public static Assembly Load(byte[] rawAssembly)
497 {
498 return Load(rawAssembly, null);
499 }
500
501 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
502 public static Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore)
503 {
504 if (rawAssembly == null)
505 {
506 throw new ArgumentNullException("rawAssembly");
507 }
508 if (rawAssembly.Length == 0)
509 {
511 }
514 return assemblyLoadContext.InternalLoad(rawAssembly, rawSymbolStore);
515 }
516
517 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
518 public static Assembly LoadFile(string path)
519 {
520 if (path == null)
521 {
522 throw new ArgumentNullException("path");
523 }
525 {
527 }
528 string fullPath = Path.GetFullPath(path);
530 {
531 if (s_loadfile.TryGetValue(fullPath, out var value))
532 {
533 return value;
534 }
536 value = assemblyLoadContext.LoadFromAssemblyPath(fullPath);
538 return value;
539 }
540 }
541
542 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
543 [UnconditionalSuppressMessage("SingleFile", "IL3000:Avoid accessing Assembly file path when publishing as a single file", Justification = "The assembly is loaded by specifying a path outside of the single-file bundle, the location of the path will not be empty if the path exist, otherwise it will be handled as null")]
545 {
546 Assembly requestingAssembly = args.RequestingAssembly;
547 if (requestingAssembly == null)
548 {
549 return null;
550 }
552 {
553 return null;
554 }
555 string fullPath = Path.GetFullPath(requestingAssembly.Location);
556 if (string.IsNullOrEmpty(fullPath))
557 {
558 return null;
559 }
561 {
562 if (!s_loadFromAssemblyList.Contains(fullPath))
563 {
565 {
567 }
568 return null;
569 }
570 }
572 string text = Path.Combine(Path.GetDirectoryName(fullPath), assemblyName.Name + ".dll");
574 {
576 }
577 try
578 {
579 return LoadFrom(text);
580 }
582 {
583 return null;
584 }
585 }
586
587 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
588 public static Assembly LoadFrom(string assemblyFile)
589 {
590 if (assemblyFile == null)
591 {
592 throw new ArgumentNullException("assemblyFile");
593 }
596 {
598 {
600 {
603 }
604 }
605 }
607 {
608 if (!s_loadFromAssemblyList.Contains(fullPath))
609 {
611 }
612 }
613 return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
614 }
615
616 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
617 public static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm)
618 {
620 }
621
622 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
624 {
625 return LoadFrom(assemblyFile);
626 }
627
628 [RequiresUnreferencedCode("Types and members the loaded module depends on might be removed")]
629 public Module LoadModule(string moduleName, byte[]? rawModule)
630 {
631 return LoadModule(moduleName, rawModule, null);
632 }
633
634 [RequiresUnreferencedCode("Types and members the loaded module depends on might be removed")]
635 public virtual Module LoadModule(string moduleName, byte[]? rawModule, byte[]? rawSymbolStore)
636 {
638 }
639
640 [Obsolete("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0018", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
641 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
646
647 [Obsolete("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0018", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
648 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
653
654 [Obsolete("ReflectionOnly loading is not supported and throws PlatformNotSupportedException.", DiagnosticId = "SYSLIB0018", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
655 [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
660}
static ? object CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture)
Definition Activator.cs:17
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static bool IsPartiallyQualified(ReadOnlySpan< char > path)
static string Combine(string path1, string path2)
Definition Path.cs:304
static string GetFullPath(string path)
Definition Path.cs:881
static ? string GetDirectoryName(string? path)
Definition Path.cs:121
static Exception ByDesign
static string EscapeCodeBase(string codebase)
static bool operator!=(Assembly? left, Assembly? right)
Definition Assembly.cs:462
virtual AssemblyName GetName(bool copiedName)
Definition Assembly.cs:299
virtual AssemblyName GetName()
Definition Assembly.cs:294
object? CreateInstance(string typeName)
Definition Assembly.cs:343
static string CreateQualifiedName(string? assemblyName, string? typeName)
Definition Assembly.cs:467
static uint GetAssemblyCount()
virtual Assembly GetSatelliteAssembly(CultureInfo culture, Version? version)
Definition Assembly.cs:401
virtual Assembly GetSatelliteAssembly(CultureInfo culture)
Definition Assembly.cs:396
object? CreateInstance(string typeName, bool ignoreCase)
Definition Assembly.cs:349
static Assembly Load(byte[] rawAssembly)
Definition Assembly.cs:496
virtual bool GlobalAssemblyCache
Definition Assembly.cs:128
static Assembly ReflectionOnlyLoad(byte[] rawAssembly)
Definition Assembly.cs:642
virtual ? Type GetType(string name, bool throwOnError)
Definition Assembly.cs:311
virtual FileStream[] GetFiles()
Definition Assembly.cs:413
virtual IList< CustomAttributeData > GetCustomAttributesData()
Definition Assembly.cs:327
static Assembly ReflectionOnlyLoad(string assemblyString)
Definition Assembly.cs:649
static Assembly GetCallingAssembly()
Definition Assembly.cs:211
static void GetEntryAssemblyNative(ObjectHandleOnStack retAssembly)
static readonly List< string > s_loadFromAssemblyList
Definition Assembly.cs:19
virtual string EscapedCodeBase
Definition Assembly.cs:114
virtual string ImageRuntimeVersion
Definition Assembly.cs:82
virtual ? Stream GetManifestResourceStream(string name)
Definition Assembly.cs:284
static Assembly Load(AssemblyName assemblyRef)
Definition Assembly.cs:185
static int s_cachedSerializationSwitch
Definition Assembly.cs:23
virtual ? string FullName
Definition Assembly.cs:74
virtual ? MethodInfo EntryPoint
Definition Assembly.cs:66
static bool s_loadFromHandlerSet
Definition Assembly.cs:21
virtual Module LoadModule(string moduleName, byte[]? rawModule, byte[]? rawSymbolStore)
Definition Assembly.cs:635
static ? Assembly GetAssembly(Type type)
Definition Assembly.cs:472
static Assembly Load(string assemblyString)
Definition Assembly.cs:157
static Assembly GetExecutingAssembly()
Definition Assembly.cs:205
override int GetHashCode()
Definition Assembly.cs:439
virtual FileStream[] GetFiles(bool getResourceModules)
Definition Assembly.cs:419
Module LoadModule(string moduleName, byte[]? rawModule)
Definition Assembly.cs:629
virtual bool IsDefined(Type attributeType, bool inherit)
Definition Assembly.cs:322
static ? Assembly GetEntryAssembly()
Definition Assembly.cs:486
static Assembly LoadFile(string path)
Definition Assembly.cs:518
override bool Equals(object? o)
Definition Assembly.cs:434
virtual ? ManifestResourceInfo GetManifestResourceInfo(string resourceName)
Definition Assembly.cs:274
virtual ? Type GetType(string name)
Definition Assembly.cs:305
virtual ? FileStream GetFile(string name)
Definition Assembly.cs:407
virtual bool ReflectionOnly
Definition Assembly.cs:100
virtual Module[] GetModules(bool getResourceModules)
Definition Assembly.cs:375
static Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore)
Definition Assembly.cs:502
virtual string[] GetManifestResourceNames()
Definition Assembly.cs:279
virtual Module ManifestModule
Definition Assembly.cs:117
override string ToString()
Definition Assembly.cs:429
virtual IEnumerable< CustomAttributeData > CustomAttributes
Definition Assembly.cs:111
static Assembly GetEntryAssemblyInternal()
Definition Assembly.cs:220
virtual Type[] GetForwardedTypes()
Definition Assembly.cs:269
static ? Assembly LoadWithPartialName(string partialName)
Definition Assembly.cs:164
virtual Module[] GetLoadedModules(bool getResourceModules)
Definition Assembly.cs:385
static Assembly ReflectionOnlyLoadFrom(string assemblyFile)
Definition Assembly.cs:656
virtual IEnumerable< TypeInfo > DefinedTypes
Definition Assembly.cs:28
virtual ? Type GetType(string name, bool throwOnError, bool ignoreCase)
Definition Assembly.cs:317
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Definition Assembly.cs:424
virtual ? Module GetModule(string name)
Definition Assembly.cs:365
static void GetExecutingAssemblyNative(StackCrawlMarkHandle stackMark, ObjectHandleOnStack retAssembly)
static readonly Dictionary< string, Assembly > s_loadfile
Definition Assembly.cs:17
static bool operator==(Assembly? left, Assembly? right)
Definition Assembly.cs:445
virtual ? ModuleResolveEventHandler ModuleResolve
Definition Assembly.cs:146
virtual object[] GetCustomAttributes(bool inherit)
Definition Assembly.cs:332
virtual IEnumerable< Type > ExportedTypes
Definition Assembly.cs:48
static Assembly LoadFrom(string assemblyFile)
Definition Assembly.cs:588
virtual ? Stream GetManifestResourceStream(Type type, string name)
Definition Assembly.cs:289
static Assembly LoadFromResolveHandler(object sender, ResolveEventArgs args)
Definition Assembly.cs:544
static RuntimeAssembly GetExecutingAssembly(ref StackCrawlMark stackMark)
Definition Assembly.cs:198
static bool s_forceNullEntryPoint
Definition Assembly.cs:25
virtual ? object CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder? binder, object[]? args, CultureInfo? culture, object[]? activationAttributes)
Definition Assembly.cs:355
virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
Definition Assembly.cs:337
virtual AssemblyName[] GetReferencedAssemblies()
Definition Assembly.cs:391
virtual ? string CodeBase
Definition Assembly.cs:58
static Assembly UnsafeLoadFrom(string assemblyFile)
Definition Assembly.cs:623
virtual Type[] GetExportedTypes()
Definition Assembly.cs:263
virtual string Location
Definition Assembly.cs:92
virtual Type[] GetTypes()
Definition Assembly.cs:237
static Assembly LoadFrom(string assemblyFile, byte[]? hashValue, AssemblyHashAlgorithm hashAlgorithm)
Definition Assembly.cs:617
virtual bool IsCollectible
Definition Assembly.cs:107
static RuntimeAssembly InternalLoad(string assemblyName, ref StackCrawlMark stackMark, AssemblyLoadContext assemblyLoadContext=null)
static bool TraceAssemblyLoadFromResolveHandlerInvoked(string assemblyName, bool isTrackedAssembly, string requestingAssemblyPath, string requestedAssemblyPath)
static ? AssemblyLoadContext CurrentContextualReflectionContext
static ? AssemblyLoadContext GetLoadContext(Assembly assembly)
static string Format_StringZeroLength
Definition SR.cs:1360
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string PlatformNotSupported_ReflectionOnly
Definition SR.cs:1792
static string NotSupported_NoTypeInfo
Definition SR.cs:1696
static string Argument_AbsolutePathRequired
Definition SR.cs:454
static string BadImageFormat_BadILFormat
Definition SR.cs:1148
static string NotSupported_AssemblyLoadFromHash
Definition SR.cs:1650
Definition SR.cs:7
delegate Module ModuleResolveEventHandler(object sender, ResolveEventArgs e)