Re: .NET/LINK USER GUIDE Comment: Calling
- To: mathgroup at smc.vnet.net
- Subject: [mg105304] Re: .NET/LINK USER GUIDE Comment: Calling
- From: fd <fdimer at gmail.com>
- Date: Fri, 27 Nov 2009 06:28:27 -0500 (EST)
- References: <he893j$q5j$1@smc.vnet.net> <hekunb$99q$1@smc.vnet.net>
On Nov 26, 3:03 pm, Todd Gayley <tgay... at wolfram.com> wrote: > Reagrs, > > Your solution is exactly correct, and you can give yourself some > well-deserved congratulations for figuring it out. You can do > arbitrarily complicated machinations with generics in .NET/Link > already, but .NET/Link really needs some added syntax for making > generics easier to use, as well as more documentation. > > One complication for your NETCallGenericStaticMethod function is that > the GetMethod call fails if the static method has overloads. You can > work around this by calling GetMethods[] and then iterating through > the list to find the one you want. I give an example of this, as well > as some more generics-related techniques, in a notebook I wrote a > little while ago called "Using LINQ from Mathematica." It is of > interest to anyone working with generics in .NET/Link, not > necessarily using LINQ. I have sent this to you separately, and I'd > be happy to send it to anyone else who is interested. Its content is > being incorporated into the .NET/Link documentation for future > versions of Mathematica. > > Todd Gayley > Wolfram Research > > At 04:47 AM 11/24/2009, wollmich wrote: > > >On 21 Nov., 09:41, wollmich <wollm... at gmail.com> wrote: > > > Hi, > > > > I've a problem to call a static generic C# method from Mathematica and > > > I don't find any example on the web or in your user guide.http://www.wolfram.com/learningcenter/tutorialcollection/NETLinkUserG... > > > > Calling a non static class (this works): > > > Type1 = LoadNETType["DummyLib.Class1"]; > > > Object1 = NETNew[Type1]; > > > Object1@Method1[]; > > > > Calling a static method in a static class (this works): > > > Type2 = LoadNETType["DummyLib.Class2"]; > > > Class2`Method2[]; > > > > Calling a non static but generic class (this works): > > > Type3 = LoadNETType["DummyLib.Class3`1[[DummyLib.Class1]]"]; > > > Object3 = NETNew[Type3]; > > > Object3@Method3[]; > > > > Calling a static generic method in a static class (THIS DOESN'T > > > WORK!!!!) I've no idea how to call it??? > > > The method could look like that in C#: > > > C#-Code: > > > namespace DummyLib > > > { > > > public static class Class4 > > > { > > > public static T Method4<T>() > > > where T : new() > > > { > > > return new T(); > > > } > > > } > > > > } > > > > With NETTypeInfo the method is listet, but I don't no idea how to pass > > > the type parameter? > > > Type4 = LoadNETType["DummyLib.Class4"]; > > > NETTypeInfo[Type4]; > > > > Can somebody please help me. Thanks. > > > > Regards Wollmich > > >I've a solution which works: > > >NETCallGenericStaticMethod[classtype_ method_, type_, arguments___] := > > Module[{m1, m2, t1, t2}, > > t1 = GetTypeObject[classtype]; > > m1 = t1@GetMethod[method]; > > t2 = GetTypeObject[type]; > > m2 = m1@MakeGenericMethod[{t2}]; > > Return[m2@Invoke[Null, arguments]]]; > > >Any other idea? > > >Reagrs Wollmich First, Congrats to wollmich, I tried to tackle this problem but I gave up, well done!! I use NET/Link quite a lot to help testing our applications and I would be interested in obtaining the document todd has mentioned, if possible, can I have a copy? Best Felipe