Assembly.GetAssembly 方法
获取在其中定义指定类的当前加载的程序集。
**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Shared Function GetAssembly ( _
type As Type _
) As Assembly
用法
Dim type As Type
Dim returnValue As Assembly
returnValue = Assembly.GetAssembly(type)
public static Assembly GetAssembly (
Type type
)
public:
static Assembly^ GetAssembly (
Type^ type
)
public static Assembly GetAssembly (
Type type
)
public static function GetAssembly (
type : Type
) : Assembly
参数
- type
Type 对象,表示将返回的程序集中的类。
返回值
在其中定义指定类的程序集。
异常
异常类型 | 条件 |
---|---|
type 为 空引用(在 Visual Basic 中为 Nothing)。 |
备注
必须拥有 Type 对象才能调用此方法,这意味着必须首先加载在其中定义该类的程序集。
示例
下面的示例检索指定类的程序集。
Dim SampleAssembly As [Assembly]
' Instantiate a target object.
Dim Integer1 As New Int32()
Dim Type1 As Type
' Set the Type instance to the target class type.
Type1 = Integer1.GetType()
' Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = [Assembly].GetAssembly(Integer1.GetType())
' Gets the location of the assembly using file: protocol.
Console.WriteLine(("CodeBase=" + SampleAssembly.CodeBase))
End Sub
Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);
Assembly^ SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
Type^ Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
// Gets the location of the assembly using file: protocol.
Console::WriteLine( "CodeBase= {0}", SampleAssembly->CodeBase );
var SampleAssembly : Assembly;
// Instantiate a target object.
var Integer1 : Int32 = 0;
var Type1 : Type;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);
.NET Framework 安全性
- ReflectionPermission 当通过类似 Type.InvokeMember 的机制以后期绑定的形式进行调用时。关联的枚举:ReflectionPermissionFlag.MemberAccess。
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0