Import 1.9b4 extra tag from cvs
[mozilla-extra.git] / extensions / mono / src / wrapped-clr.cs
blob39862749b127da2acf14867fff482241510d6c4d
1 using System;
2 using System.Reflection;
3 using System.Runtime.InteropServices;
4 using Mozilla.XPCOM;
6 using MethodDescriptor = Mozilla.XPCOM.TypeInfo.MethodDescriptor;
7 using ParamDescriptor = Mozilla.XPCOM.TypeInfo.ParamDescriptor;
8 using ParamFlags = Mozilla.XPCOM.TypeInfo.ParamFlags;
9 using TypeDescriptor = Mozilla.XPCOM.TypeInfo.TypeDescriptor;
10 using TypeFlags = Mozilla.XPCOM.TypeInfo.TypeFlags;
11 using TypeTag = Mozilla.XPCOM.TypeInfo.TypeTag;
13 namespace Mozilla.XPCOM {
14 internal class CLRWrapper
16 public static IntPtr Wrap(object o, ref Guid iid)
18 CLRWrapper wrapper = new CLRWrapper(o, ref iid);
19 return wrapper.MakeXPCOMProxy();
22 int InvokeMethod(int index, IntPtr args)
24 Console.WriteLine("invoking method {0} on {1}", index,
25 wrappedObj);
26 MethodDescriptor desc = TypeInfo.GetMethodData(wrappedAsIID, index);
27 Type ifaceType = TypeInfo.TypeForIID(wrappedAsIID);
28 // Console.WriteLine("ifaceType: {0}", ifaceType);
29 MethodInfo meth = ifaceType.GetMethod(desc.name);
30 // Console.WriteLine("meth: {0}", meth);
31 // This might just throw on you, if it's not a void-taking method
32 meth.Invoke(wrappedObj, new object[0]);
33 return 0;
36 CLRWrapper(object o, ref Guid iid)
38 wrappedObj = o;
39 wrappedAsIID = iid;
42 object wrappedObj;
43 Guid wrappedAsIID;
45 delegate int MethodInvoker(int index, IntPtr args);
47 [DllImport("xpcom-dotnet.so")]
48 static extern IntPtr WrapCLRObject(MethodInvoker del, ref Guid iid);
50 IntPtr MakeXPCOMProxy()
52 return WrapCLRObject(new MethodInvoker(this.InvokeMethod),
53 ref wrappedAsIID);
57 } // namespace Mozilla.XPCOM