Re: [Ikvm-developers] Question about ikvmstub and .NET generics
Brought to you by:
jfrijters
From: Gluck, J. <Jan...@ph...> - 2010-09-08 12:19:37
|
Hi Jeroen, Thank you very much! I will give this a try. Janice -----Original Message----- From: Jeroen Frijters [mailto:je...@su...] Sent: Wednesday, September 08, 2010 12:00 AM To: Gluck, Janice; ikv...@li... Subject: RE: Question about ikvmstub and .NET generics Hi, Java doesn't support reified generics and I don't know of any way to reasonbly fake it, so ikvmstub doesn't export generic methods. You could write a small non-generic wrapper in C# that calls the generic method, or if there aren't very many methods, you could use .NET reflection (from Java) to call the Add method. Here's an example of using a delegate to call a generic method: import cli.System.AsyncCallback; import cli.System.Activator; import cli.System.Delegate; import cli.System.IAsyncResult; import cli.System.MulticastDelegate; import cli.System.Type; import cli.System.Collections.IList; import ikvm.runtime.Util; class GenericMethod { public static final class AddDelegate extends MulticastDelegate { public AddDelegate(Method m) { } public native void Invoke(GenericMethod obj); public interface Method { void Invoke(GenericMethod obj); } } public static void main(String[] args) { IList list = (IList)Activator.CreateInstance( Type.GetType("System.Collections.Generic.List`1"). MakeGenericType(Util.getInstanceTypeFromClass(GenericMethod.class)) ); AddDelegate add = (AddDelegate)Delegate.CreateDelegate( Util.getInstanceTypeFromClass(AddDelegate.class), list, "Add"); add.Invoke(new GenericMethod()); add.Invoke(new GenericMethod()); add.Invoke(new GenericMethod()); for (int i = 0; i < list.get_Count(); i++) { System.out.println(list.get_Item(i)); } } } Regards, Jeroen > -----Original Message----- > From: Gluck, Janice [mailto:Jan...@ph...] > Sent: Tuesday, September 07, 2010 10:05 PM > To: ikv...@li... > Subject: [Ikvm-developers] Question about ikvmstub and .NET generics > > Hello, > > I am new to IKVM.NET. I am a java developer.... > > I need to write code that interacts with .NET assemblies from a third > party vendor (so the .NET code can't be changed).. > > I ran ikvmstub against the exe provided by the vendor and java stub > classes were generated but for the key class I need to use > > Any methods that had generics as parameters were not included in the > java stub class: > > For example: > > In the DataStore class (.net) - per the vendor's doco there should be a > method: > > Add<(Of <(T>)>)(T) > <mk:@MSITStore:C:\geotabinfo\CheckmateSdk.chm::/html/cdab33d4-a27b-67df- > 2c89-ab08a5e2d4b8.htm> > > But when I look in the generated DataStore java class, there is no Add > method of any kind. (I decompiled the stub class)... > > Is it possible to get these methods to generate using ikvmstub or is > there another workaround I can try? > > I need to be able to access the .NET code from java....and I can't change > the .net side of things... > > Thank you for your help! > > Janice |