public static void Main () { Bus bus = Bus.Session; string bus_name = "org.ndesk.test"; ObjectPath path = new ObjectPath ("/org/ndesk/test"); ObjectPath cppath = new ObjectPath ("/org/ndesk/CodeProvider"); IDemoOne demo; if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) { //create a new instance of the object to be exported demo = new Demo (); bus.Register (path, demo); DCodeProvider dcp = new DCodeProvider(); bus.Register (cppath, dcp); //run the main loop while (true) bus.Iterate (); } else { //import a remote to a local proxy //demo = bus.GetObject<IDemo> (bus_name, path); demo = bus.GetObject<DemoProx> (bus_name, path); //RunTest (demo); ICodeProvider idcp = bus.GetObject<ICodeProvider> (bus_name, cppath); DMethodInfo dmi = idcp.GetMethod ("DemoProx", "SayRepeatedly"); DArgumentInfo[] fields = idcp.GetFields ("DemoProx"); foreach (DArgumentInfo field in fields) Console.WriteLine("Field: " + field.Name); //DynamicMethod dm = new DynamicMethod (dmi.Name, typeof(void), new Type[] { typeof(object), typeof(int), typeof(string) }, typeof(DemoBase)); //ILGenerator ilg = dm.GetILGenerator (); //dmi.Implement (ilg); DynamicMethod dm = dmi.GetDM (); SayRepeatedlyHandler cb = (SayRepeatedlyHandler)dm.CreateDelegate (typeof (SayRepeatedlyHandler), demo); int retVal; retVal = cb (12, "Works!"); Console.WriteLine("retVal: " + retVal); /* for (int i = 0 ; i != dmi.Code.Length ; i++) { if (!dmi.Code[i].Emit(ilg)) throw new Exception(String.Format("Code gen failure at i={0} {1}", i, dmi.Code[i].opCode)); } */ //SayRepeatedlyHandler } }
public static void Main() { Bus bus = Bus.Session; string bus_name = "org.ndesk.test"; ObjectPath path = new ObjectPath("/org/ndesk/test"); ObjectPath cppath = new ObjectPath("/org/ndesk/CodeProvider"); IDemoOne demo; if (bus.RequestName(bus_name) == RequestNameReply.PrimaryOwner) { //create a new instance of the object to be exported demo = new Demo(); bus.Register(path, demo); DCodeProvider dcp = new DCodeProvider(); bus.Register(cppath, dcp); //run the main loop while (true) { bus.Iterate(); } } else { //import a remote to a local proxy //demo = bus.GetObject<IDemo> (bus_name, path); demo = bus.GetObject <DemoProx> (bus_name, path); //RunTest (demo); ICodeProvider idcp = bus.GetObject <ICodeProvider> (bus_name, cppath); DMethodInfo dmi = idcp.GetMethod("DemoProx", "SayRepeatedly"); DArgumentInfo[] fields = idcp.GetFields("DemoProx"); foreach (DArgumentInfo field in fields) { Console.WriteLine("Field: " + field.Name); } //DynamicMethod dm = new DynamicMethod (dmi.Name, typeof(void), new Type[] { typeof(object), typeof(int), typeof(string) }, typeof(DemoBase)); //ILGenerator ilg = dm.GetILGenerator (); //dmi.Implement (ilg); DynamicMethod dm = dmi.GetDM(); SayRepeatedlyHandler cb = (SayRepeatedlyHandler)dm.CreateDelegate(typeof(SayRepeatedlyHandler), demo); int retVal; retVal = cb(12, "Works!"); Console.WriteLine("retVal: " + retVal); /* * for (int i = 0 ; i != dmi.Code.Length ; i++) { * if (!dmi.Code[i].Emit(ilg)) * throw new Exception(String.Format("Code gen failure at i={0} {1}", i, dmi.Code[i].opCode)); * } */ //SayRepeatedlyHandler } }