Activator.CreateInstanceFrom 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用具名組件檔案和最符合指定參數的建構函式,建立已具有指定名稱之類型的執行個體。
多載
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
物件,使用 bindingAttr
和 args
來搜尋及識別 typeName
建構函式。 如果 binder
為 null
,則會使用預設繫結器。
- args
- Object[]
符合建構函式要叫用之參數的數目、順序和類型的引數陣列。 如果 args
是空陣列或 null
,則會叫用未採用參數的建構函式 (無參數建構函式)。
- culture
- CultureInfo
特定文化特性的資訊,其可控制 args
到型式類型 (為 typeName
建構函式宣告) 的強制轉型。 如果 culture
為 null
,會使用目前執行緒的 CultureInfo。
- activationAttributes
- Object[]
一或多個屬性的陣列,此屬性可參與啟動過程。 陣列通常只會包含一個 UrlAttribute 物件來指定用以啟動遠端物件的 URL。
此參數與啟動了用戶端的物件相關。 用戶端啟動是一項舊的技術,保留目的在提供回溯相容性,不建議用於新的開發。 分散式應用程式應該改用 Windows Communication Foundation。
- securityAttributes
- Evidence
用來執行安全性原則決策和授權程式碼使用權限的資訊。
傳回
必須解除包裝的控制碼,才能存取新建立的物件或 null
Nullable<T> 實例。
- 屬性
例外狀況
domain
或 typeName
為 null
。
找不到相符的建構函式。
在 assemblyFile
中找不到 typename
。
找不到 assemblyFile
。
呼叫端沒有呼叫這個建構函式的權限。
無法建立抽象類別的執行個體,或者這個成員曾被晚期繫結機制叫用過。
透過反映叫用並擲回例外狀況的建構函式。
呼叫端具有所要求的 FileIOPermission。
activationAttributes
不是空的陣列,而建立中的類型不是衍生自 MarshalByRefObject。
assemblyFile
不是有效的組件。
-或-
目前載入的是 Common Language Runtime (CLR) 2.0 版或更新版本,且已使用比目前載入之版本更新的 CLR 版本來編譯 assemblyName
。 請注意,.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
物件,使用 bindingAttr
和 args
來搜尋及識別 typeName
建構函式。 如果 binder
為 null
,則會使用預設繫結器。
- args
- Object[]
符合建構函式要叫用之參數的數目、順序和類型的引數陣列。 如果 args
是空陣列或 null
,則會叫用未採用參數的建構函式 (無參數建構函式)。
- culture
- CultureInfo
特定文化特性的資訊,其可控制 args
到型式類型 (為 typeName
建構函式宣告) 的強制轉型。 如果 culture
為 null
,會使用目前執行緒的 CultureInfo。
- activationAttributes
- Object[]
一或多個屬性的陣列,此屬性可參與啟動過程。 陣列通常只會包含一個 UrlAttribute 物件來指定用以啟動遠端物件的 URL。
此參數與啟動了用戶端的物件相關。 用戶端啟動是一項舊的技術,保留目的在提供回溯相容性,不建議用於新的開發。 分散式應用程式應該改用 Windows Communication Foundation。
- securityInfo
- Evidence
用來執行安全性原則決策和授權程式碼使用權限的資訊。
傳回
必須解除包裝的控制碼,才能存取新建立的物件或 null
Nullable<T> 實例。
- 屬性
例外狀況
typeName
為 null
。
找不到相符的建構函式。
在 assemblyFile
中找不到 typename
。
找不到 assemblyFile
。
呼叫端沒有呼叫這個建構函式的權限。
無法建立抽象類別的執行個體,或者這個成員曾被晚期繫結機制叫用過。
透過反映叫用並擲回例外狀況的建構函式。
呼叫端沒有所要求的 FileIOPermission。
activationAttributes
不是空的陣列,而建立中的類型不是衍生自 MarshalByRefObject。
assemblyFile
不是有效的組件。
-或-
目前載入的是 Common Language Runtime (CLR) 2.0 版或更新版本,且已使用比目前載入之版本更新的 CLR 版本來編譯 assemblyName
。 請注意,.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
物件,使用 bindingAttr
和 args
來搜尋及識別 typeName
建構函式。 如果 binder
為 null
,則會使用預設繫結器。
- args
- Object[]
符合建構函式要叫用之參數的數目、順序和類型的引數陣列。 如果 args
是空陣列或 null
,則會叫用未採用參數的建構函式 (無參數建構函式)。
- culture
- CultureInfo
特定文化特性的資訊,其可控制 args
到型式類型 (為 typeName
建構函式宣告) 的強制轉型。 如果 culture
為 null
,會使用目前執行緒的 CultureInfo。
- activationAttributes
- Object[]
一或多個屬性的陣列,此屬性可參與啟動過程。 陣列通常只會包含一個 UrlAttribute 物件來指定用以啟動遠端物件的 URL。
此參數與啟動了用戶端的物件相關。 用戶端啟動是一項舊的技術,保留目的在提供回溯相容性,不建議用於新的開發。 分散式應用程式應該改用 Windows Communication Foundation。
傳回
必須解除包裝的控制碼,才能存取新建立的物件或 null
Nullable<T> 實例。
- 屬性
例外狀況
domain
或 typeName
為 null
。
找不到相符的建構函式。
在 assemblyFile
中找不到 typename
。
找不到 assemblyFile
。
呼叫端沒有呼叫這個建構函式的權限。
無法建立抽象類別的執行個體,或者這個成員曾被晚期繫結機制叫用過。
透過反映叫用並擲回例外狀況的建構函式。
呼叫端具有所要求的 FileIOPermission。
activationAttributes
不是空的陣列,而建立中的類型不是衍生自 MarshalByRefObject。
assemblyFile
不是有效的組件。
-或-
assemblyName
已針對比目前載入版本更新的 Common Language Runtime 進行編譯。
備註
當主機需要在具有限制安全性許可權的應用程式域中執行程式碼時,請使用 CreateInstanceFrom 。
ObjectHandle.Unwrap使用 方法來解除包裝傳回值。
如需其他可由叫用方法擲回之例外狀況的資訊,請參閱 和 CreateInstance 方法的 Assembly.LoadFrom 例外狀況區段。
適用於
CreateInstanceFrom(String, String, Object[])
- 來源:
- Activator.cs
- 來源:
- Activator.cs
- 來源:
- 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> 實例。
例外狀況
typeName
為 null
。
找不到相符的公用建構函式。
在 assemblyFile
中找不到 typename
。
找不到 assemblyFile
。
呼叫端沒有呼叫這個建構函式的權限。
無法建立抽象類別的執行個體,或者這個成員曾被晚期繫結機制叫用過。
透過反映叫用並擲回例外狀況的建構函式。
activationAttributes
不是空的陣列,而建立中的類型不是衍生自 MarshalByRefObject。
呼叫端具有所要求的 FileIOPermission。
assemblyFile
不是有效的組件。
-或-
目前載入的是 Common Language Runtime (CLR) 2.0 版或更新版本,且已使用比目前載入之版本更新的 CLR 版本來編譯 assemblyName
。 請注意,.NET Framework 2.0、3.0 和 3.5 版全部都會使用 CLR 2.0 版。
備註
ObjectHandle.Unwrap使用 方法來解除包裝傳回值。
如需其他可由叫用方法擲回之例外狀況的資訊,請參閱 和 CreateInstance 方法的 Assembly.LoadFrom Exceptions 一節。
適用於
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> 實例。
- 屬性
例外狀況
domain
或 typeName
為 null
。
找不到相符的公用建構函式。
在 assemblyFile
中找不到 typename
。
找不到 assemblyFile
。
呼叫端沒有呼叫這個建構函式的權限。
無法建立抽象類別的執行個體,或者這個成員曾被晚期繫結機制叫用過。
透過反映叫用並擲回例外狀況的建構函式。
呼叫端具有所要求的 FileIOPermission。
assemblyFile
不是有效的組件。
-或-
目前載入的是 Common Language Runtime (CLR) 2.0 版或更新版本,且已使用比目前載入之版本更新的 CLR 版本來編譯 assemblyName
。 請注意,.NET Framework 2.0、3.0 和 3.5 版全部都會使用 CLR 2.0 版。
備註
當主機需要在具有限制安全性許可權的應用程式域中執行程式碼時,請使用 CreateInstanceFrom 。
ObjectHandle.Unwrap使用 方法來解除包裝傳回值。
如需其他可由叫用方法擲回之例外狀況的資訊,請參閱 和 CreateInstance 方法的 Assembly.LoadFrom Exceptions 一節。
適用於
CreateInstanceFrom(String, String)
- 來源:
- Activator.cs
- 來源:
- Activator.cs
- 來源:
- 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> 實例。
例外狀況
typeName
為 null
。
找不到相符的公用建構函式。
在 assemblyFile
中找不到 typename
。
找不到 assemblyFile
。
呼叫端沒有呼叫這個建構函式的權限。
無法建立抽象類別的執行個體,或者這個成員曾被晚期繫結機制叫用過。
透過反映叫用並擲回例外狀況的建構函式。
呼叫端具有所要求的 FileIOPermission。
assemblyFile
不是有效的組件。
-或-
目前載入的是 Common Language Runtime (CLR) 2.0 版或更新版本,且已使用比目前載入之版本更新的 CLR 版本來編譯 assemblyName
。 請注意,.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 Exceptions 一節。
適用於
CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])
- 來源:
- Activator.cs
- 來源:
- Activator.cs
- 來源:
- 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
物件,使用 bindingAttr
和 args
來搜尋及識別 typeName
建構函式。 如果 binder
為 null
,則會使用預設繫結器。
- args
- Object[]
符合建構函式要叫用之參數的數目、順序和類型的引數陣列。 如果 args
是空陣列或 null
,則會叫用未採用參數的建構函式 (無參數建構函式)。
- culture
- CultureInfo
特定文化特性的資訊,其可控制 args
到型式類型 (為 typeName
建構函式宣告) 的強制轉型。 如果 culture
為 null
,會使用目前執行緒的 CultureInfo。
- activationAttributes
- Object[]
一或多個屬性的陣列,此屬性可參與啟動過程。 陣列通常只會包含一個 UrlAttribute 物件來指定用以啟動遠端物件的 URL。
此參數與啟動了用戶端的物件相關。 用戶端啟動是一項舊的技術,保留目的在提供回溯相容性,不建議用於新的開發。 分散式應用程式應該改用 Windows Communication Foundation。
傳回
必須解除包裝的控制碼,才能存取新建立的物件或 null
Nullable<T> 實例。
例外狀況
typeName
為 null
。
找不到相符的建構函式。
在 assemblyFile
中找不到 typename
。
找不到 assemblyFile
。
呼叫端沒有呼叫這個建構函式的權限。
無法建立抽象類別的執行個體,或者這個成員曾被晚期繫結機制叫用過。
透過反映叫用並擲回例外狀況的建構函式。
呼叫端沒有所要求的 FileIOPermission。
activationAttributes
不是空的陣列,而建立中的類型不是衍生自 MarshalByRefObject。
assemblyFile
不是有效的組件。
-或-
目前載入的是 Common Language Runtime (CLR) 2.0 版或更新版本,且已使用比目前載入之版本更新的 CLR 版本來編譯 assemblyName
。 請注意,.NET Framework 2.0、3.0 和 3.5 版全部都會使用 CLR 2.0 版。
備註
ObjectHandle.Unwrap使用 方法來解除包裝傳回值。
如需其他可由叫用方法擲回之例外狀況的資訊,請參閱 和 CreateInstance 方法的 Assembly.LoadFrom Exceptions 一節。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應