Assembly 类
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示一个程序集,该程序集是公共语言运行时应用程序的可重用、可版本控制且自描述的构建基块。
public ref class Assembly abstract
public ref class Assembly abstract : System::Reflection::ICustomAttributeProvider, System::Runtime::Serialization::ISerializable
public ref class Assembly abstract : System::Reflection::ICustomAttributeProvider
public ref class Assembly : System::Reflection::ICustomAttributeProvider, System::Runtime::InteropServices::_Assembly, System::Runtime::Serialization::ISerializable, System::Security::IEvidenceFactory
public ref class Assembly abstract : System::Reflection::ICustomAttributeProvider, System::Runtime::InteropServices::_Assembly, System::Runtime::Serialization::ISerializable, System::Security::IEvidenceFactory
public abstract class Assembly
public abstract class Assembly : System.Reflection.ICustomAttributeProvider, System.Runtime.Serialization.ISerializable
public abstract class Assembly : System.Reflection.ICustomAttributeProvider
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
public class Assembly : System.Reflection.ICustomAttributeProvider, System.Runtime.InteropServices._Assembly, System.Runtime.Serialization.ISerializable, System.Security.IEvidenceFactory
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class Assembly : System.Reflection.ICustomAttributeProvider, System.Runtime.InteropServices._Assembly, System.Runtime.Serialization.ISerializable, System.Security.IEvidenceFactory
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Assembly : System.Reflection.ICustomAttributeProvider, System.Runtime.InteropServices._Assembly, System.Runtime.Serialization.ISerializable, System.Security.IEvidenceFactory
type Assembly = class
type Assembly = class
interface ICustomAttributeProvider
interface ISerializable
type Assembly = class
interface ICustomAttributeProvider
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
type Assembly = class
interface _Assembly
interface IEvidenceFactory
interface ICustomAttributeProvider
interface ISerializable
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Assembly = class
interface _Assembly
interface IEvidenceFactory
interface ICustomAttributeProvider
interface ISerializable
Public MustInherit Class Assembly
Public MustInherit Class Assembly
Implements ICustomAttributeProvider, ISerializable
Public MustInherit Class Assembly
Implements ICustomAttributeProvider
Public Class Assembly
Implements _Assembly, ICustomAttributeProvider, IEvidenceFactory, ISerializable
Public MustInherit Class Assembly
Implements _Assembly, ICustomAttributeProvider, IEvidenceFactory, ISerializable
- 继承
-
Assembly
- 派生
- 属性
- 实现
下面的代码示例演示如何获取当前正在执行的程序集,创建该程序集中包含的类型的实例,以及调用具有后期绑定的类型之一的方法。 为此,代码示例使用名为 SampleMethod
的方法定义名为 Example
的类。 类的构造函数接受整数,该整数用于计算方法的返回值。
该代码示例还演示了如何使用 GetName 方法获取可用于分析程序集全名的 AssemblyName 对象。 该示例显示程序集的版本号、CodeBase 属性和 EntryPoint 属性。
using namespace System;
using namespace System::Reflection;
using namespace System::Security::Permissions;
[assembly:AssemblyVersionAttribute("1.0.2000.0")];
public ref class Example
{
private:
int factor;
public:
Example(int f)
{
factor = f;
}
int SampleMethod(int x)
{
Console::WriteLine("\nExample->SampleMethod({0}) executes.", x);
return x * factor;
}
};
void main()
{
Assembly^ assem = Example::typeid->Assembly;
Console::WriteLine("Assembly Full Name:");
Console::WriteLine(assem->FullName);
// The AssemblyName type can be used to parse the full name.
AssemblyName^ assemName = assem->GetName();
Console::WriteLine("\nName: {0}", assemName->Name);
Console::WriteLine("Version: {0}.{1}",
assemName->Version->Major, assemName->Version->Minor);
Console::WriteLine("\nAssembly CodeBase:");
Console::WriteLine(assem->CodeBase);
// Create an object from the assembly, passing in the correct number and
// type of arguments for the constructor.
Object^ o = assem->CreateInstance("Example", false,
BindingFlags::ExactBinding,
nullptr, gcnew array<Object^> { 2 }, nullptr, nullptr);
// Make a late-bound call to an instance method of the object.
MethodInfo^ m = assem->GetType("Example")->GetMethod("SampleMethod");
Object^ ret = m->Invoke(o, gcnew array<Object^> { 42 });
Console::WriteLine("SampleMethod returned {0}.", ret);
Console::WriteLine("\nAssembly entry point:");
Console::WriteLine(assem->EntryPoint);
}
/* This code example produces output similar to the following:
Assembly Full Name:
source, Version=1.0.2000.0, Culture=neutral, PublicKeyToken=null
Name: source
Version: 1.0
Assembly CodeBase:
file:///C:/sdtree/AssemblyClass/cpp/source.exe
Example->SampleMethod(42) executes.
SampleMethod returned 84.
Assembly entry point:
UInt32 _mainCRTStartup()
*/
using System;
using System.Reflection;
using System.Security.Permissions;
[assembly:AssemblyVersionAttribute("1.0.2000.0")]
public class Example
{
private int factor;
public Example(int f)
{
factor = f;
}
public int SampleMethod(int x)
{
Console.WriteLine("\nExample.SampleMethod({0}) executes.", x);
return x * factor;
}
public static void Main()
{
Assembly assem = typeof(Example).Assembly;
Console.WriteLine("Assembly Full Name:");
Console.WriteLine(assem.FullName);
// The AssemblyName type can be used to parse the full name.
AssemblyName assemName = assem.GetName();
Console.WriteLine("\nName: {0}", assemName.Name);
Console.WriteLine("Version: {0}.{1}",
assemName.Version.Major, assemName.Version.Minor);
Console.WriteLine("\nAssembly CodeBase:");
Console.WriteLine(assem.CodeBase);
// Create an object from the assembly, passing in the correct number
// and type of arguments for the constructor.
Object o = assem.CreateInstance("Example", false,
BindingFlags.ExactBinding,
null, new Object[] { 2 }, null, null);
// Make a late-bound call to an instance method of the object.
MethodInfo m = assem.GetType("Example").GetMethod("SampleMethod");
Object ret = m.Invoke(o, new Object[] { 42 });
Console.WriteLine("SampleMethod returned {0}.", ret);
Console.WriteLine("\nAssembly entry point:");
Console.WriteLine(assem.EntryPoint);
}
}
/* This code example produces output similar to the following:
Assembly Full Name:
source, Version=1.0.2000.0, Culture=neutral, PublicKeyToken=null
Name: source
Version: 1.0
Assembly CodeBase:
file:///C:/sdtree/AssemblyClass/cs/source.exe
Example.SampleMethod(42) executes.
SampleMethod returned 84.
Assembly entry point:
Void Main()
*/
Imports System.Reflection
Imports System.Security.Permissions
<assembly: AssemblyVersionAttribute("1.0.2000.0")>
Public Class Example
Private factor As Integer
Public Sub New(ByVal f As Integer)
factor = f
End Sub
Public Function SampleMethod(ByVal x As Integer) As Integer
Console.WriteLine(vbCrLf & "Example.SampleMethod({0}) executes.", x)
Return x * factor
End Function
Public Shared Sub Main()
Dim assem As Assembly = GetType(Example).Assembly
Console.WriteLine("Assembly Full Name:")
Console.WriteLine(assem.FullName)
' The AssemblyName type can be used to parse the full name.
Dim assemName As AssemblyName = assem.GetName()
Console.WriteLine(vbLf + "Name: {0}", assemName.Name)
Console.WriteLine("Version: {0}.{1}", assemName.Version.Major, _
assemName.Version.Minor)
Console.WriteLine(vbLf + "Assembly CodeBase:")
Console.WriteLine(assem.CodeBase)
' Create an object from the assembly, passing in the correct number
' and type of arguments for the constructor.
Dim o As Object = assem.CreateInstance("Example", False, _
BindingFlags.ExactBinding, Nothing, _
New Object() { 2 }, Nothing, Nothing)
' Make a late-bound call to an instance method of the object.
Dim m As MethodInfo = assem.GetType("Example").GetMethod("SampleMethod")
Dim ret As Object = m.Invoke(o, New Object() { 42 })
Console.WriteLine("SampleMethod returned {0}.", ret)
Console.WriteLine(vbCrLf & "Assembly entry point:")
Console.WriteLine(assem.EntryPoint)
End Sub
End Class
' This code example produces output similar to the following:
'
'Assembly Full Name:
'source, Version=1.0.2000.0, Culture=neutral, PublicKeyToken=null
'
'Name: source
'Version: 1.0
'
'Assembly CodeBase:
'file:///C:/sdtree/AssemblyClass/vb/source.exe
'
'Example.SampleMethod(42) executes.
'SampleMethod returned 84.
'
'Assembly entry point:
'Void Main()
'
使用 Assembly 类加载程序集、浏览程序集的元数据和构成部分、发现程序集中包含的类型以及创建这些类型的实例。
若要获取表示当前加载到应用程序域(例如简单项目的默认应用程序域)的程序集的 Assembly 对象的数组,请使用 AppDomain.GetAssemblies 方法。
为了动态加载程序集,Assembly 类提供以下静态方法(Visual Basic 中的Shared
方法)。 程序集将加载到发生加载操作的应用程序域中。
加载程序集的建议方法是使用 Load 方法,该方法标识要按其显示名称加载的程序集(例如“System.Windows.Forms,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”)。 搜索程序集遵循 运行时如何定位程序集中所述的规则。
ReflectionOnlyLoad 和 ReflectionOnlyLoadFrom 方法使你可以加载用于反射的程序集,但不能用于执行。 例如,面向 64 位平台的程序集可以通过在 32 位平台上运行的代码进行检查。
若要获取当前正在执行的程序集的 Assembly 对象,请使用 GetExecutingAssembly 方法。
Assembly 类的许多成员提供有关程序集的信息。 例如:
GetName 方法返回一个 AssemblyName 对象,该对象提供对程序集显示名称部分的访问权限。
GetCustomAttributes 方法列出了应用于程序集的属性。
GetFiles 方法提供对程序集清单中的文件的访问权限。
GetManifestResourceNames 方法提供程序集清单中资源的名称。
GetTypes 方法列出程序集中的所有类型。 GetExportedTypes 方法列出了程序集外部调用方可见的类型。 GetType 方法可用于搜索程序集中的特定类型。 CreateInstance 方法可用于在程序集中搜索和创建类型的实例。
有关程序集的详细信息,请参阅 应用程序域 主题中的“应用程序域和程序集”部分。
Assembly() |
初始化 Assembly 类的新实例。 |
Code |
已过时.
已过时.
获取最初指定的程序集的位置,例如,在 AssemblyName 对象中。 |
Custom |
获取包含此程序集的自定义属性的集合。 |
Defined |
获取此程序集中定义的类型的集合。 |
Entry |
获取此程序集的入口点。 |
Escaped |
已过时.
已过时.
获取表示代码库的 URI(包括转义字符)。 |
Evidence |
获取此程序集的证据。 |
Exported |
获取此程序集中定义的公共类型的集合,这些类型在程序集外部可见。 |
Full |
获取程序集的显示名称。 |
Global |
已过时.
获取一个值,该值指示程序集是否已从全局程序集缓存(.NET Framework)加载。 |
Host |
获取加载程序集的主机上下文。 |
Image |
获取一个字符串,该字符串表示包含在包含清单的文件中保存的公共语言运行时 (CLR) 的版本。 |
Is |
获取一个值,该值指示此程序集是否保存在可收集 AssemblyLoadContext中。 |
Is |
获取一个值,该值指示当前程序集是否使用反射发出在当前进程中动态生成。 |
Is |
获取一个值,该值指示当前程序集是否使用完全信任加载。 |
Location |
获取包含清单的已加载文件的完整路径或 UNC 位置。 |
Manifest |
获取包含当前程序集清单的模块。 |
Modules |
获取包含此程序集中的模块的集合。 |
Permission |
获取当前程序集的授权集。 |
Reflection |
获取一个 Boolean 值,该值指示此程序集是否已加载到仅反射上下文中。 |
Security |
获取一个值,该值指示公共语言运行时(CLR)为此程序集强制执行的安全规则集。 |
Create |
找到此程序集中的指定类型,并使用系统激活器(使用区分大小写的搜索)创建它的实例。 |
Create |
查找此程序集中的指定类型,并使用系统激活器创建它的实例,以及可选的区分大小写的搜索。 |
Create |
从此程序集中找到指定的类型,并使用系统激活器创建它的实例,并具有可选的区分大小写的搜索,并具有指定的区域性、参数以及绑定和激活属性。 |
Create |
创建由程序集的显示名称限定的类型的名称。 |
Equals(Object) |
确定此程序集和指定的对象是否相等。 |
Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
Get |
获取当前加载的程序集,在该程序集中定义指定类型。 |
Get |
返回调用当前正在执行的方法的 Assembly。 |
Get |
获取此程序集的所有自定义属性。 |
Get |
按类型获取此程序集的自定义属性。 |
Get |
返回已应用于当前 Assembly的属性的信息,这些属性表示为 CustomAttributeData 对象。 |
Get |
获取正在运行的应用程序的条目程序集。 |
Get |
获取包含当前正在执行的代码的程序集。 |
Get |
获取在此程序集中定义的公共类型,这些类型在程序集外部可见。 |
Get |
获取此程序集清单的文件表中指定文件的 FileStream。 |
Get |
获取程序集清单的文件表中的文件。 |
Get |
获取程序集清单的文件表中的文件,指定是否包含资源模块。 |
Get |
表示一个程序集,该程序集是公共语言运行时应用程序的可重用、可版本控制且自描述的构建基块。 |
Get |
返回此实例的哈希代码。 |
Get |
用作默认哈希函数。 (继承自 Object) |
Get |
获取属于此程序集的所有已加载模块。 |
Get |
获取属于此程序集的所有已加载模块,指定是否包含资源模块。 |
Get |
返回有关如何持久保存给定资源的信息。 |
Get |
返回此程序集中所有资源的名称。 |
Get |
从此程序集加载指定的清单资源。 |
Get |
从此程序集加载由指定类型的命名空间限定的指定清单资源。 |
Get |
获取此程序集中的指定模块。 |
Get |
获取属于此程序集的所有模块。 |
Get |
获取属于此程序集的所有模块,指定是否包含资源模块。 |
Get |
获取此程序集的 AssemblyName。 |
Get |
获取此程序集的 AssemblyName,设置由 |
Get |
已过时.
获取序列化信息,其中包含重新初始化此程序集所需的所有数据。 |
Get |
获取此程序集引用的所有程序集的 AssemblyName 对象。 |
Get |
获取指定区域性的附属程序集。 |
Get |
获取指定区域性的附属程序集的指定版本。 |
Get |
表示一个程序集,该程序集是公共语言运行时应用程序的可重用、可版本控制且自描述的构建基块。 |
Get |
获取当前实例的 Type。 (继承自 Object) |
Get |
获取程序集实例中具有指定名称的 Type 对象。 |
Get |
获取程序集实例中具有指定名称的 Type 对象,并选择性地在找不到类型时引发异常。 |
Get |
获取程序集实例中具有指定名称的 Type 对象,以及忽略大小写的选项,并在找不到类型时引发异常。 |
Get |
获取此程序集中定义的所有类型。 |
Is |
指示是否已将指定的属性应用于程序集。 |
Load(Assembly |
根据程序集的 AssemblyName加载程序集。 |
Load(Assembly |
已过时.
根据程序集的 AssemblyName加载程序集。 使用提供的证据加载程序集。 |
Load(Byte[]) |
使用基于公共对象文件格式(COFF)的图像加载程序集,其中包含发出的程序集。 |
Load(Byte[], Byte[]) |
使用基于通用对象文件格式(COFF)的图像加载程序集,其中包含所发出的程序集(可选)包括程序集的符号。 |
Load(Byte[], Byte[], Evidence) |
已过时.
使用基于通用对象文件格式(COFF)的图像加载程序集,其中包含所发出的程序集(可选)包括程序集的符号和证据。 |
Load(Byte[], Byte[], Security |
使用基于通用对象文件格式(COFF)的图像加载程序集,其中包含发出的程序集,可以选择包括符号并指定安全上下文的源。 |
Load(String) |
加载具有指定名称的程序集。 |
Load(String, Evidence) |
已过时.
加载给定程序集的显示名称并使用提供的证据。 |
Load |
加载指定路径上的程序集文件的内容。 |
Load |
已过时.
根据程序集的路径加载程序集,使用提供的证据加载程序集。 |
Load |
加载给定其文件名或路径的程序集。 |
Load |
已过时.
根据程序集的文件名或路径、哈希值和哈希算法加载程序集。 |
Load |
已过时.
加载给定程序集的文件名或路径并提供安全证据。 |
Load |
已过时.
根据程序集的文件名或路径、安全证据、哈希值和哈希算法加载程序集。 |
Load |
将模块加载到此程序集的内部,其中包含一个基于公共对象文件格式(COFF)的图像,其中包含发出的模块或资源文件。 |
Load |
将模块加载到此程序集的内部,其中包含一个基于公共对象文件格式(COFF)的图像,其中包含发出的模块或资源文件。 还将加载表示模块符号的原始字节。 |
Load |
已过时.
已过时.
已过时.
使用部分名称从应用程序目录或全局程序集缓存加载程序集。 |
Load |
已过时.
使用部分名称从应用程序目录或全局程序集缓存加载程序集。 使用提供的证据加载程序集。 |
Memberwise |
创建当前 Object的浅表副本。 (继承自 Object) |
Reflection |
已过时.
从基于公共对象文件格式(COFF)的图像加载程序集,其中包含发出的程序集。 程序集加载到调用方应用程序域的仅反射上下文中。 |
Reflection |
已过时.
给定程序集的显示名称,将程序集加载到仅反射上下文中。 |
Reflection |
已过时.
给定程序集的路径,将程序集加载到仅反射上下文中。 |
Set |
将应用程序的条目程序集设置为提供的程序集对象。 |
To |
返回程序集的完整名称,也称为显示名称。 |
Unsafe |
将程序集加载到从上下文中加载,绕过一些安全检查。 |
Equality(Assembly, Assembly) |
指示两个 Assembly 对象是否相等。 |
Inequality(Assembly, Assembly) |
指示两个 Assembly 对象是否不相等。 |
Module |
当公共语言运行时类加载程序无法通过正常方式解析对程序集内部模块的引用时发生。 |
_Assembly. |
返回当前实例的类型。 |
ICustom |
返回此成员上定义的所有自定义属性的数组,不包括命名属性,如果没有自定义属性,则返回空数组。 |
ICustom |
返回在此成员上定义的自定义属性的数组(按类型标识)或空数组(如果没有该类型的自定义属性)。 |
ICustom |
指示是否在此成员上定义了一个或多个 |
Get |
表示一个程序集,该程序集是公共语言运行时应用程序的可重用、可版本控制且自描述的构建基块。 |
Get |
表示一个程序集,该程序集是公共语言运行时应用程序的可重用、可版本控制且自描述的构建基块。 |
Get |
表示一个程序集,该程序集是公共语言运行时应用程序的可重用、可版本控制且自描述的构建基块。 |
Get |
检索应用于指定程序集的指定类型的自定义属性。 |
Get |
检索应用于指定程序集的指定类型的自定义属性。 |
Get |
检索应用于指定程序集的自定义属性的集合。 |
Get |
检索应用于指定程序集的指定类型的自定义属性集合。 |
Get |
检索应用于指定程序集的指定类型的自定义属性集合。 |
Is |
指示指定类型的自定义属性是否应用于指定的程序集。 |
Try |
检索程序集的元数据部分,以用于 MetadataReader。 |
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
此类型是线程安全的。