[C#] クラスの動的生成あれこれ(その3)
そういやこのシリーズ、ずーっと間違ってたけど、クラスを動的生成しているわけではなくて、動的にクラス情報を取得してオブジェクトを構築しているだけなんですよね・・。なので、実行時に取得したクラス情報からオブジェクトを構築する方法とでもしないといけないのだが、もう修正するのもめんどくさいので、このままでいいや(^^;
- Activator.CreateInstance (String, String, Object[]) のサンプル
昨日のサーバが動いているとして、
Assembly assem = Assembly.GetAssembly(typeof(RemotingSamples.HelloServer));
object[] activationAttributes =
{new System.Runtime.Remoting.Activation.UrlAttribute("tcp://localhost:8085/HelloService")};
System.Runtime.Remoting.ObjectHandle objHandle =
System.Activator.CreateInstance(assem.FullName, "RemotingSamples.HelloServer", activationAttributes);RemotingSamples.HelloServer hs = objHandle.Unwrap() as RemotingSamples.HelloServer;
hs.HelloMethod("hoge");
- Activator.CreateInstance (Type, BindingFlags, Binder, Object[], CultureInfo) のサンプル
System.Console.WriteLine("Main の Activator.CreateInstance (Type, BindingFlags, Binder, Object[], CultureInfo) のサンプル");
C c = Activator.CreateInstance( typeof(C), BindingFlags.CreateInstance, null, null, new System.Globalization.CultureInfo("ja-JP") ) as C;
c.func();