コード例 #1
0
ファイル: TestRental.cs プロジェクト: JazzCF/BA_CF
    public DMethodInfo GetMethod(string iface, string name)
    {
        DMethodInfo dmi = new DMethodInfo();

        dmi.Name = name;
        dmi.DeclaringInterface = new DTypeInfo(iface);

        Type       declType = dmi.DeclaringInterface.ToType();
        MethodInfo mi       = declType.GetMethod(name);

        List <string> locals = new List <string>();
        MethodBody    body   = mi.GetMethodBody();

        foreach (LocalVariableInfo lvar in body.LocalVariables)
        {
            locals.Add(lvar.LocalType.FullName);
        }
        dmi.Body.Locals = locals.ToArray();

        List <DTypeInfo> parms = new List <DTypeInfo>();

        foreach (ParameterInfo parm in mi.GetParameters())
        {
            parms.Add(new DTypeInfo(parm.ParameterType.FullName));
        }
        dmi.Parameters = parms.ToArray();

        dmi.ReturnType = new DTypeInfo(mi.ReturnType.FullName);

        ILReader2 ilr = new ILReader2(mi);

        dmi.Body.Code = ilr.Iterate();

        return(dmi);
    }
コード例 #2
0
ファイル: TestRental.cs プロジェクト: brookpatten/dbus-sharp
	public DMethodInfo GetMethod (string iface, string name)
	{
		DMethodInfo dmi = new DMethodInfo ();

		dmi.Name = name;
		dmi.DeclaringInterface = new DTypeInfo(iface);

		Type declType = dmi.DeclaringInterface.ToType();
		MethodInfo mi = declType.GetMethod(name);

		List<string> locals = new List<string>();
		MethodBody body = mi.GetMethodBody ();
		foreach (LocalVariableInfo lvar in body.LocalVariables)
			locals.Add(lvar.LocalType.FullName);
		dmi.Body.Locals = locals.ToArray();

		List<DTypeInfo> parms = new List<DTypeInfo>();
		foreach (ParameterInfo parm in mi.GetParameters())
			parms.Add(new DTypeInfo(parm.ParameterType.FullName));
		dmi.Parameters = parms.ToArray();

		dmi.ReturnType = new DTypeInfo(mi.ReturnType.FullName);

		ILReader2 ilr = new ILReader2(mi);
		dmi.Body.Code = ilr.Iterate();

		return dmi;
	}
コード例 #3
0
ファイル: TestRental.cs プロジェクト: JazzCF/BA_CF
    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
        }
    }