Activator.CreateInstanceFrom 方法

定义

使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。

重载

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
已过时.

使用命名的程序集文件和最匹配所指定参数的构造函数,来创建其名称在指定的远程域中指定的类型的实例。

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
已过时.

使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

使用命名的程序集文件和最匹配所指定参数的构造函数,来创建其名称在指定的远程域中指定的类型的实例。

CreateInstanceFrom(String, String, Object[])

使用已命名的程序集文件和无参数构造函数,创建名称已指定的类型的实例。

CreateInstanceFrom(AppDomain, String, String)

使用已命名的程序集文件和无参数构造函数,来创建其名称在指定的远程域中指定的类型的实例。

CreateInstanceFrom(String, String)

使用已命名的程序集文件和无参数构造函数,创建名称已指定的类型的实例。

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

注意

Methods which use Evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

使用命名的程序集文件和最匹配所指定参数的构造函数,来创建其名称在指定的远程域中指定的类型的实例。

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(AppDomain ^ domain, System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes, System::Security::Policy::Evidence ^ securityAttributes);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityAttributes);
[System.Obsolete("Methods which use Evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityAttributes);
static member CreateInstanceFrom : AppDomain * string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
[<System.Obsolete("Methods which use Evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
[<System.Security.SecurityCritical>]
static member CreateInstanceFrom : AppDomain * string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (domain As AppDomain, assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object(), securityAttributes As Evidence) As ObjectHandle

参数

domain
AppDomain

在其中创建名为 typeName 的类型的远程域。

assemblyFile
String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。

typeName
String

要为其创建实例的类型的名称。

ignoreCase
Boolean

使用 true 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。

bindingAttr
BindingFlags

影响 typeName 构造函数搜索的零个或多个位标志的组合。 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。

binder
Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。 如果 bindernull,则使用默认联编程序。

args
Object[]

与要调用的构造函数的参数的编号、顺序和类型匹配的参数数组。 如果 args 为空数组或 null,则调用不带任何参数的构造函数(无参数构造函数)。

culture
CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。 如果 culturenull,则使用当前线程的 CultureInfo

activationAttributes
Object[]

包含一个或多个可以参与激活的特性的数组。 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。

此参数与客户端激活的对象相关。 客户端激活是一项传统技术,保留用于向后兼容,但不建议用于新的开发。 应改用 Windows Communication Foundation 来开发分布式应用程序。

securityAttributes
Evidence

用于做出安全策略决策和授予代码权限的信息。

返回

必须取消包装才能访问新创建的对象或 null 实例 Nullable<T> 的句柄。

属性

例外

domaintypeNamenull

未找到匹配的构造函数。

assemblyFile 中未找到 typename

未找到 assemblyFile

调用方没有权限调用此构造函数。

无法创建抽象类的实例,或者此成员是使用晚期绑定机制调用的。

通过反射调用的构造函数引发异常。

调用方确实具有所需的 FileIOPermission

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。

assemblyFile 不是有效的程序集。

- 或 -

当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。

注解

当主机需要在具有受限安全权限的应用程序域中执行代码时使用 CreateInstanceFrom

ObjectHandle.Unwrap使用 方法解包返回值。

有关可由调用的方法引发的其他异常的信息,请参阅 和 CreateInstance 方法的 Assembly.LoadFrom Exceptions 部分。

适用于

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

注意

Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes, System::Security::Policy::Evidence ^ securityInfo);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityInfo);
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityInfo);
static member CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
[<System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
static member CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object(), securityInfo As Evidence) As ObjectHandle

参数

assemblyFile
String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。

typeName
String

要为其创建实例的类型的名称。

ignoreCase
Boolean

使用 true 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。

bindingAttr
BindingFlags

影响 typeName 构造函数搜索的零个或多个位标志的组合。 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。

binder
Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。 如果 bindernull,则使用默认联编程序。

args
Object[]

与要调用的构造函数的参数的编号、顺序和类型匹配的参数数组。 如果 args 为空数组或 null,则调用不带任何参数的构造函数(无参数构造函数)。

culture
CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。 如果 culturenull,则使用当前线程的 CultureInfo

activationAttributes
Object[]

包含一个或多个可以参与激活的特性的数组。 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。

此参数与客户端激活的对象相关。 客户端激活是一项传统技术,保留用于向后兼容,但不建议用于新的开发。 应改用 Windows Communication Foundation 来开发分布式应用程序。

securityInfo
Evidence

用于做出安全策略决策和授予代码权限的信息。

返回

必须取消包装才能访问新创建的对象或 null 实例 Nullable<T> 的句柄。

属性

例外

typeNamenull

未找到匹配的构造函数。

assemblyFile 中未找到 typename

未找到 assemblyFile

调用方没有权限调用此构造函数。

无法创建抽象类的实例,或者此成员是使用晚期绑定机制调用的。

通过反射调用的构造函数引发异常。

调用方没有所要求的 FileIOPermission

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。

assemblyFile 不是有效的程序集。

- 或 -

当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。

注解

ObjectHandle.Unwrap使用 方法解包返回值。

有关可由调用的方法引发的其他异常的信息,请参阅 和 CreateInstance 方法的 Assembly.LoadFrom Exceptions 部分。

适用于

CreateInstanceFrom(AppDomain, String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

使用命名的程序集文件和最匹配所指定参数的构造函数,来创建其名称在指定的远程域中指定的类型的实例。

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(AppDomain ^ domain, System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes);
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes);
[<System.Security.SecurityCritical>]
static member CreateInstanceFrom : AppDomain * string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (domain As AppDomain, assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object()) As ObjectHandle

参数

domain
AppDomain

在其中创建名为 typeName 的类型的远程域。

assemblyFile
String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。

typeName
String

要为其创建实例的类型的名称。

ignoreCase
Boolean

使用 true 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。

bindingAttr
BindingFlags

影响 typeName 构造函数搜索的零个或多个位标志的组合。 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。

binder
Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。 如果 bindernull,则使用默认联编程序。

args
Object[]

与要调用的构造函数的参数的编号、顺序和类型匹配的参数数组。 如果 args 为空数组或 null,则调用不带任何参数的构造函数(无参数构造函数)。

culture
CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。 如果 culturenull,则使用当前线程的 CultureInfo

activationAttributes
Object[]

包含一个或多个可以参与激活的特性的数组。 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。

此参数与客户端激活的对象相关。 客户端激活是一项传统技术,保留用于向后兼容,但不建议用于新的开发。 应改用 Windows Communication Foundation 来开发分布式应用程序。

返回

必须解包才能访问新创建的对象或 null 实例 Nullable<T> 的句柄。

属性

例外

domaintypeNamenull

未找到匹配的构造函数。

assemblyFile 中未找到 typename

未找到 assemblyFile

调用方没有权限调用此构造函数。

无法创建抽象类的实例,或者此成员是使用晚期绑定机制调用的。

通过反射调用的构造函数引发异常。

调用方确实具有所需的 FileIOPermission

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。

assemblyFile 不是有效的程序集。

- 或 -

assemblyName 是针对晚于当前加载版本的公共语言运行时版本编译的。

注解

当主机需要在具有受限安全权限的应用程序域中执行代码时使用 CreateInstanceFrom

ObjectHandle.Unwrap使用 方法可解包返回值。

有关可由调用的方法引发的其他异常的信息,请参阅 和 CreateInstance 方法的Assembly.LoadFrom异常部分。

适用于

CreateInstanceFrom(String, String, Object[])

Source:
Activator.cs
Source:
Activator.cs
Source:
Activator.cs

使用已命名的程序集文件和无参数构造函数,创建名称已指定的类型的实例。

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, cli::array <System::Object ^> ^ activationAttributes);
public static System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom (string assemblyFile, string typeName, object?[]? activationAttributes);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, object[] activationAttributes);
static member CreateInstanceFrom : string * string * obj[] -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String, activationAttributes As Object()) As ObjectHandle

参数

assemblyFile
String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。

typeName
String

要为其创建实例的类型的名称。

activationAttributes
Object[]

包含一个或多个可以参与激活的特性的数组。 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。

此参数与客户端激活的对象相关。 客户端激活是一项传统技术,保留用于向后兼容,但不建议用于新的开发。 应改用 Windows Communication Foundation 来开发分布式应用程序。

返回

必须解包才能访问新创建的对象或 null 实例 Nullable<T> 的句柄。

例外

typeNamenull

未找到匹配的公共构造函数。

assemblyFile 中未找到 typename

未找到 assemblyFile

调用方没有权限调用此构造函数。

无法创建抽象类的实例,或者此成员是使用晚期绑定机制调用的。

通过反射调用的构造函数引发异常。

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。

调用方确实具有所需的 FileIOPermission

assemblyFile 不是有效的程序集。

- 或 -

当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。

注解

ObjectHandle.Unwrap使用 方法可解包返回值。

有关可由调用的方法引发的其他异常的信息,请参阅 和 CreateInstance 方法的Assembly.LoadFrom异常部分。

适用于

CreateInstanceFrom(AppDomain, String, String)

使用已命名的程序集文件和无参数构造函数,来创建其名称在指定的远程域中指定的类型的实例。

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(AppDomain ^ domain, System::String ^ assemblyFile, System::String ^ typeName);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName);
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName);
static member CreateInstanceFrom : AppDomain * string * string -> System.Runtime.Remoting.ObjectHandle
[<System.Security.SecurityCritical>]
static member CreateInstanceFrom : AppDomain * string * string -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (domain As AppDomain, assemblyFile As String, typeName As String) As ObjectHandle

参数

domain
AppDomain

在其中创建名为 typeName 的类型的远程域。

assemblyFile
String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。

typeName
String

要为其创建实例的类型的名称。

返回

必须解包才能访问新创建的对象或 null 实例 Nullable<T> 的句柄。

属性

例外

domaintypeNamenull

未找到匹配的公共构造函数。

assemblyFile 中未找到 typename

未找到 assemblyFile

调用方没有权限调用此构造函数。

无法创建抽象类的实例,或者此成员是使用晚期绑定机制调用的。

通过反射调用的构造函数引发异常。

调用方确实具有所需的 FileIOPermission

assemblyFile 不是有效的程序集。

- 或 -

当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。

注解

当主机需要在具有受限安全权限的应用程序域中执行代码时使用 CreateInstanceFrom

ObjectHandle.Unwrap使用 方法可解包返回值。

有关可由调用的方法引发的其他异常的信息,请参阅 和 CreateInstance 方法的Assembly.LoadFrom异常部分。

适用于

CreateInstanceFrom(String, String)

Source:
Activator.cs
Source:
Activator.cs
Source:
Activator.cs

使用已命名的程序集文件和无参数构造函数,创建名称已指定的类型的实例。

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName);
public static System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom (string assemblyFile, string typeName);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName);
static member CreateInstanceFrom : string * string -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String) As ObjectHandle

参数

assemblyFile
String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。

typeName
String

要为其创建实例的类型的名称。

返回

必须解包才能访问新创建的对象或 null 实例 Nullable<T> 的句柄。

例外

typeNamenull

未找到匹配的公共构造函数。

assemblyFile 中未找到 typename

未找到 assemblyFile

调用方没有权限调用此构造函数。

无法创建抽象类的实例,或者此成员是使用晚期绑定机制调用的。

通过反射调用的构造函数引发异常。

调用方确实具有所需的 FileIOPermission

assemblyFile 不是有效的程序集。

- 或 -

当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。

示例

下面的代码示例演示如何调用 CreateInstanceFrom 方法。 此代码示例是为 Activator 类提供的一个更大示例的一部分。

// Create an instance of the SomeType class that is defined in this 
// assembly.
System::Runtime::Remoting::ObjectHandle^ oh = 
    Activator::CreateInstanceFrom(Assembly::GetEntryAssembly()->CodeBase, 
                                  SomeType::typeid->FullName);

// Call an instance method defined by the SomeType type using this object.
SomeType^ st = (SomeType^) oh->Unwrap();

st->DoSomething(5);
// Create an instance of the SomeType class that is defined in this
// assembly.
System.Runtime.Remoting.ObjectHandle oh =
    Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase,
                                 typeof(SomeType).FullName);

// Call an instance method defined by the SomeType type using this object.
SomeType st = (SomeType) oh.Unwrap();

st.DoSomething(5);
// Create an instance of the SomeType class that is defined in this assembly.
let oh = 
    Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().Location, typeof<SomeType>.FullName)

// Call an instance method defined by the SomeType type using this object.
let st = oh.Unwrap() :?> SomeType

st.DoSomething 5
' Create an instance of the SomeType class that is defined in this assembly.
Dim oh As System.Runtime.Remoting.ObjectHandle = _
    Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase, _
                                 GetType(SomeType).FullName)

' Call an instance method defined by the SomeType type using this object.
Dim st As SomeType = CType(oh.Unwrap(), SomeType)

st.DoSomething(5)

注解

ObjectHandle.Unwrap使用 方法可解包返回值。

有关可由调用的方法引发的其他异常的信息,请参阅 和 CreateInstance 方法的Assembly.LoadFrom异常部分。

适用于

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Source:
Activator.cs
Source:
Activator.cs
Source:
Activator.cs

使用指定的程序集文件和与指定参数匹配程度最高的构造函数来创建指定名称的类型的实例。

public:
 static System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes);
public static System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes);
public static System.Runtime.Remoting.ObjectHandle CreateInstanceFrom (string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes);
static member CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] -> System.Runtime.Remoting.ObjectHandle
Public Shared Function CreateInstanceFrom (assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object()) As ObjectHandle

参数

assemblyFile
String

包含某程序集的文件的名称,将在该程序集内查找名为 typeName 的类型。

typeName
String

要为其创建实例的类型的名称。

ignoreCase
Boolean

使用 true 指定对 typeName 的搜索不区分大小写;使用 false 则指定搜索区分大小写。

bindingAttr
BindingFlags

影响 typeName 构造函数搜索的零个或多个位标志的组合。 如果 bindingAttr 为零,则对公共构造函数进行区分大小写的搜索。

binder
Binder

使用 bindingAttrargs 来查找和标识 typeName 构造函数的对象。 如果 bindernull,则使用默认联编程序。

args
Object[]

与要调用的构造函数的参数的编号、顺序和类型匹配的参数数组。 如果 args 为空数组或 null,则调用不带任何参数的构造函数(无参数构造函数)。

culture
CultureInfo

区域性特定的信息,这些信息控制将 args 强制转换为 typeName 构造函数所声明的正式类型。 如果 culturenull,则使用当前线程的 CultureInfo

activationAttributes
Object[]

包含一个或多个可以参与激活的特性的数组。 这通常为包含单个 UrlAttribute 对象的数组,该对象指定激活远程对象所需的 URL。

此参数与客户端激活的对象相关。 客户端激活是一项传统技术,保留用于向后兼容,但不建议用于新的开发。 应改用 Windows Communication Foundation 来开发分布式应用程序。

返回

必须取消包装才能访问新创建的对象或 null 实例 Nullable<T> 的句柄。

例外

typeNamenull

未找到匹配的构造函数。

assemblyFile 中未找到 typename

未找到 assemblyFile

调用方没有权限调用此构造函数。

无法创建抽象类的实例,或者此成员是使用晚期绑定机制调用的。

通过反射调用的构造函数引发异常。

调用方没有所要求的 FileIOPermission

activationAttributes 不是空数组,且正在创建的类型不是从 MarshalByRefObject 派生得来的。

assemblyFile 不是有效的程序集。

- 或 -

当前已加载公共语言运行时 (CLR) 2.0 或更新版本,但 assemblyName 是使用比当前加载版本更新的 CLR 版本编译的。 请注意,.NET Framework 2.0、3.0 和 3.5 都使用 CLR 2.0。

注解

ObjectHandle.Unwrap使用 方法解包返回值。

有关可由调用的方法引发的其他异常的信息,请参阅 和 CreateInstance 方法的 Assembly.LoadFrom Exceptions 部分。

适用于