Message Boards Message Boards

GROUPS:

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

Posted 8 months ago
948 Views
|
2 Replies
|
2 Total Likes
|
2 Replies

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

Posted 8 months ago

Hi,

Thank you for your feedback. I looked at the link, but the example did not help me.

During searching on the Internet I found another interesting link:

https://stackoverflow.com/questions/232535/how-do-i-use-reflection-to-call-a-generic-method

and this link helped me.

I rewrote the last line to the following C# form:

System.Reflection.MethodInfo method = typeof(SpaceMyClass.MyClass).GetMethod("column");      
System.Reflection.MethodInfo generic = method.MakeGenericMethod(typeof(string)); 
object returnValue=generic.Invoke(myClass, new object[1] { 0 });

Then I rewrote it to the Mathematica

typeMyClass=LoadNETType["SpaceMyClass.MyClass"];
method=GetTypeObject[typeMyClass]@GetMethod["column"];
typeString=LoadNETType["string"];
generic=method@MakeGenericMethod[{GetTypeObject[typeString]}];
st=generic@Invoke[form,{0}]

And this works!

I hope it will help other users who also try the .NET Link

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

Group Abstract Group Abstract