MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: .NET/LINK USER GUIDE Comment: Calling static generic C# method

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105193] Re: .NET/LINK USER GUIDE Comment: Calling static generic C# method
  • From: wollmich <wollmich at gmail.com>
  • Date: Tue, 24 Nov 2009 05:47:06 -0500 (EST)
  • References: <he893j$q5j$1@smc.vnet.net>

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.wolf=
ram.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


  • Prev by Date: Re: How to get the output of FindFit from MathLink in
  • Next by Date: Re: Is it possible to make NIntegrate faster?
  • Previous by thread: .NET/LINK USER GUIDE Comment: Calling static generic C# method
  • Next by thread: Finding multiple value in Complex Analysis