次の方法で共有


Activator.CreateInstanceFrom メソッド

名前を指定したアセンブリ ファイルと、指定したパラメータに最も一致するコンストラクタを使用して、名前を指定した型のインスタンスを作成します。

オーバーロードの一覧

名前を指定したアセンブリ ファイルと、既定のコンストラクタを使用して、名前を指定した型のインスタンスを作成します。

[Visual Basic] Overloads Public Shared Function CreateInstanceFrom(String, String) As ObjectHandle

[C#] public static ObjectHandle CreateInstanceFrom(string, string);

[C++] public: static ObjectHandle* CreateInstanceFrom(String*, String*);

[JScript] public static function CreateInstanceFrom(String, String) : ObjectHandle;

名前を指定したアセンブリ ファイルと、既定のコンストラクタを使用して、名前を指定した型のインスタンスを作成します。

[Visual Basic] Overloads Public Shared Function CreateInstanceFrom(String, String, Object()) As ObjectHandle

[C#] public static ObjectHandle CreateInstanceFrom(string, string, object[]);

[C++] public: static ObjectHandle* CreateInstanceFrom(String*, String*, Object[]);

[JScript] public static function CreateInstanceFrom(String, String, Object[]) : ObjectHandle;

名前を指定したアセンブリ ファイルと、指定したパラメータに最も一致するコンストラクタを使用して、名前を指定した型のインスタンスを作成します。

[Visual Basic] Overloads Public Shared Function CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object(), CultureInfo, Object(), Evidence) As ObjectHandle

[C#] public static ObjectHandle CreateInstanceFrom(string, string, bool, BindingFlags, Binder, object[], CultureInfo, object[], Evidence);

[C++] public: static ObjectHandle* CreateInstanceFrom(String*, String*, bool, BindingFlags, Binder*, Object[], CultureInfo*, Object[], Evidence*);

[JScript] public static function CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence) : ObjectHandle;

使用例

[Visual Basic, C#, JScript] CreateInstanceFrom メソッドのオーバーロードの例を次に示します。

[Visual Basic, C#, JScript] メモ   ここでは、CreateInstanceFrom のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Dim hdlSample As ObjectHandle
Dim myExtenderInterface As IMyExtenderInterface
Dim activationAttributes() = {New SynchronizationAttribute()}

' Assumes that SampleAssembly.dll exists in the same directory as this assembly.
hdlSample = Activator.CreateInstanceFrom("SampleAssembly.dll", "SampleNamespace.SampleClass", activationAttributes)
' Assumes that the SampleClass implements an interface provided by
' this application.
myExtenderInterface = CType(hdlSample.Unwrap(), IMyExtenderInterface)
Console.WriteLine(myExtenderInterface.SampleMethod("Bill"))

[C#] 
ObjectHandle            hdlSample;
IMyExtenderInterface    myExtenderInterface;
object[]                activationAttributes = {new SynchronizationAttribute()};

// Assumes that SampleAssembly.dll exists in the same directory as this assembly.
hdlSample = Activator.CreateInstanceFrom("SampleAssembly.dll", "SampleNamespace.SampleClass", activationAttributes);
// Assumes that the SampleClass implements an interface provided by
// this application.
myExtenderInterface = (IMyExtenderInterface)hdlSample.Unwrap();
Console.WriteLine(myExtenderInterface.SampleMethod("Bill"));

[JScript] 
var hdlSample : ObjectHandle;
var myExtenderInterface : IMyExtenderInterface;
var activationAttributes : Object[] = [new SynchronizationAttribute()];

// Assumes that SampleAssembly.dll exists in the same directory as this assembly.
hdlSample = Activator.CreateInstanceFrom("SampleAssembly.dll", "SampleNamespace.SampleClass", activationAttributes);
// Assumes that the SampleClass implements an interface provided by
// this application.
myExtenderInterface = IMyExtenderInterface(hdlSample.Unwrap());
Console.WriteLine(myExtenderInterface.SampleMethod("Bill"));

[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Activator クラス | Activator メンバ | System 名前空間