2 using System
.Reflection
;
3 using System
.Runtime
.InteropServices
;
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
,
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]);
36 CLRWrapper(object o
, ref Guid iid
)
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
),
57 } // namespace Mozilla.XPCOM