Group Abstract Group Abstract

Message Boards Message Boards

Use C# generic method in Mathematica .NET/Link?

Posted 8 years ago

Hi,

I'm trying to call an external method in the Mathematica, but I do not know how to do it. Do you have any experience with calling generic methods from Mathematica? Generic methods are a powerful tool, but I do not know how to connect them to Mathematica.

There is the fragment of my code in C# (only for information):

namespace SpaceMyClass
{

public class MyClass 
{
List<object[]> element;
int elementLen = 0;

public void fillElements()
{
… //function for add elements to List 

}

 public T[] column<T>(int x)
        {
            T[] res = new T[elementLen];
            for (int i = 0; i < elementLen; i++)
            {
                res[i] = (T)element[i][x];
            }
            return res;
        }
}
}

I would like to convert this C# code into Mathematica:

SpaceMyClass.MyClass form = new SpaceMyClass.MyClass();
form.fillElements();
string[] st = form.column<string>(0);

I tried this code:

Needs["NETLink`"];
InstallNET[];
LoadNETAssembly[NotebookDirectory[]<>"SpaceMyClass.dll"];  
form=NETNew["SpaceMyClass.MyClass"];
form@fillElements[];

But I do not know how to rewrite last line to Mathematica:

string[] st = myClass.column<string>(0);

Because the code contains <string> and I can not find in Mathematica help or elsewhere how to do it.

I'll be glad for any ideas on how to keep the generics method and use it in Mathematica

POSTED BY: Mirek M
2 Replies
Posted 8 years ago
POSTED BY: Mirek M

You may want to try MakeNETObject. Take a look at this similar question with JLink

POSTED BY: Shenghui Yang
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard