#unity/日常积累
AppDomain.GetAssemblies 方法
定义
命名空间:
System
程序集:
System.Runtime.dll
获取已加载到此应用程序域的执行上下文中的程序集。
1
|
public System.Reflection.Assembly[] GetAssemblies ();
|
返回
Assembly[]
此应用程序域中的程序集的数组。
例外
AppDomainUnloadedException
在卸载的应用程序域上尝试该操作。
示例
下面的代码示例使用 GetAssemblies 该方法获取已加载到应用程序域的所有程序集的列表。 然后,程序集会显示到控制台。
若要运行此代码示例,需要创建一 CustomLibrary.dll
个名为的程序集,或更改传递给该方法的 GetAssemblies 程序集名称。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
using System;
using System.Reflection;
using System.Security.Policy;
class ADGetAssemblies
{
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
//Provide the current application domain evidence for the assembly.
Evidence asEvidence = currentDomain.Evidence;
//Load the assembly from the application directory using a simple name.
//Create an assembly called CustomLibrary to run this sample.
currentDomain.Load("CustomLibrary",asEvidence);
//Make an array for the list of assemblies.
Assembly[] assems = currentDomain.GetAssemblies();
//List the assemblies in the current application domain.
Console.WriteLine("List of assemblies loaded in current appdomain:");
foreach (Assembly assem in assems)
Console.WriteLine(assem.ToString());
}
}
|