public object ComplexAsVariant(object v, int num) { Console.WriteLine("v: " + v); Console.WriteLine("v null? " + (v == null)); MyTuple2 mt2 = (MyTuple2)Convert.ChangeType(v, typeof(MyTuple2)); Console.WriteLine("mt2.C[3].B " + mt2.C[3].B); Console.WriteLine("num: " + num); return(v); }
public static void Main () { Bus bus = Bus.Session; string bus_name = "org.ndesk.test"; ObjectPath path = new ObjectPath ("/org/ndesk/test"); 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); //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); } Console.WriteLine (); demo.SomeEvent += HandleSomeEventA; demo.FireOffSomeEvent (); Console.WriteLine (); demo.SomeEvent -= HandleSomeEventA; demo.FireOffSomeEvent (); Console.WriteLine (); demo.SomeEvent += delegate (string arg1, object arg2, double arg3, MyTuple mt) {Console.WriteLine ("SomeEvent handler: " + arg1 + ", " + arg2 + ", " + arg3 + ", " + mt.A + ", " + mt.B);}; demo.SomeEvent += delegate (string arg1, object arg2, double arg3, MyTuple mt) {Console.WriteLine ("SomeEvent handler two: " + arg1 + ", " + arg2 + ", " + arg3 + ", " + mt.A + ", " + mt.B);}; demo.FireOffSomeEvent (); Console.WriteLine (); Console.WriteLine (demo.GetSomeVariant ()); Console.WriteLine (); demo.Say2 ("demo.Say2"); ((IDemoTwo)demo).Say2 ("((IDemoTwo)demo).Say2"); demo.SayEnum (DemoEnum.Bar, DemoEnum.Foo); uint n; string ostr; demo.WithOutParameters (out n, "21", out ostr); Console.WriteLine ("n: " + n); Console.WriteLine ("ostr: " + ostr); uint[] a1, a2, a3; demo.WithOutParameters2 (out a1, out a2, out a3); Console.WriteLine ("oparam2: " + a2[1]); uint[] @contacts = new uint[] { 2 }; IDictionary<uint,SimplePresence> presence; demo.GetPresences (contacts, out presence); Console.WriteLine ("pres: " + presence[2].Status); MyTuple2 cpx = new MyTuple2 (); cpx.A = "a"; cpx.B = "b"; cpx.C = new Dictionary<int,MyTuple> (); cpx.C[3] = new MyTuple("foo", "bar"); object cpxRet = demo.ComplexAsVariant (cpx, 12); MyTuple2 mt2ret = (MyTuple2)Convert.ChangeType (cpxRet, typeof (MyTuple2)); Console.WriteLine ("mt2ret.C[3].B " + mt2ret.C[3].B); /* IDemoOne[] objs = demo.GetObjArr (); foreach (IDemoOne obj in objs) obj.Say ("Some obj"); */ Console.WriteLine("SomeProp: " + demo.SomeProp); demo.SomeProp = 321; DemoProx demoProx = demo as DemoProx; if (demoProx != null) demoProx.SayRepeatedly(5, "Repetition"); demo.ThrowSomeException (); }
public static void Main() { Bus bus = Bus.Session; string bus_name = "org.ndesk.test"; ObjectPath path = new ObjectPath("/org/ndesk/test"); 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); //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); } Console.WriteLine(); demo.SomeEvent += HandleSomeEventA; demo.FireOffSomeEvent(); Console.WriteLine(); demo.SomeEvent -= HandleSomeEventA; demo.FireOffSomeEvent(); Console.WriteLine(); demo.SomeEvent += delegate(string arg1, object arg2, double arg3, MyTuple mt) { Console.WriteLine("SomeEvent handler: " + arg1 + ", " + arg2 + ", " + arg3 + ", " + mt.A + ", " + mt.B); }; demo.SomeEvent += delegate(string arg1, object arg2, double arg3, MyTuple mt) { Console.WriteLine("SomeEvent handler two: " + arg1 + ", " + arg2 + ", " + arg3 + ", " + mt.A + ", " + mt.B); }; demo.FireOffSomeEvent(); Console.WriteLine(); Console.WriteLine(demo.GetSomeVariant()); Console.WriteLine(); demo.Say2("demo.Say2"); ((IDemoTwo)demo).Say2("((IDemoTwo)demo).Say2"); demo.SayEnum(DemoEnum.Bar, DemoEnum.Foo); uint n; string ostr; demo.WithOutParameters(out n, "21", out ostr); Console.WriteLine("n: " + n); Console.WriteLine("ostr: " + ostr); uint[] a1, a2, a3; demo.WithOutParameters2(out a1, out a2, out a3); Console.WriteLine("oparam2: " + a2[1]); uint[] @contacts = new uint[] { 2 }; IDictionary <uint, SimplePresence> presence; demo.GetPresences(contacts, out presence); Console.WriteLine("pres: " + presence[2].Status); MyTuple2 cpx = new MyTuple2(); cpx.A = "a"; cpx.B = "b"; cpx.C = new Dictionary <int, MyTuple> (); cpx.C[3] = new MyTuple("foo", "bar"); object cpxRet = demo.ComplexAsVariant(cpx, 12); MyTuple2 mt2ret = (MyTuple2)Convert.ChangeType(cpxRet, typeof(MyTuple2)); Console.WriteLine("mt2ret.C[3].B " + mt2ret.C[3].B); /* * IDemoOne[] objs = demo.GetObjArr (); * foreach (IDemoOne obj in objs) * obj.Say ("Some obj"); */ Console.WriteLine("SomeProp: " + demo.SomeProp); demo.SomeProp = 321; DemoProx demoProx = demo as DemoProx; if (demoProx != null) { demoProx.SayRepeatedly(5, "Repetition"); } demo.ThrowSomeException(); }