Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using .net custom classes within matlab

Tags:

.net

class

matlab

I'm currently using Matlab to import a custom dot NET dll library I have,
using AssemblyInfo = NET.addAssembly('c:\myClasses.dll').

listing disp(AssemblyInfo.Classes) expose the custom classes of the library, like

'MyLib.ClassA'  
'MyLib.ClassB'  
'MyLib.ClassA+eResults'  

I'm using myVar = MyLib.ClassA; to create a .net class variable within matlab (which works fine),
but the second class has no constructor, so myVar = MyLib.ClassB; results in
No constructor 'MyLib.ClassB' with matching signature found.

The second issue is the plus sign (+) at the .NET class MyLib.ClassA+eResults,
of which causing an error when I try myVar = MyLib.ClassA+eResults;
Undefined function or variable 'eResults'.

Is there a way to create an instance custom class MyLib.ClassB within matlab?
What is the plus sign means, and how do I create an instance of MyLib.ClassA+eResults without any syntax error?

like image 762
shahar_m Avatar asked Feb 17 '23 17:02

shahar_m


1 Answers

To create an instance of a class, it must be public and have public constructors. If the classB has only a custom constructor with multiple parameters, you can instantiate it like this:

var = MyLib.ClassB(x, y);

for the second issue, the + means eResults is a nested class of ClassA. You can't instantiante directly, but there is a workaround based on reflection described here: Working With Nested Classes:

a = NET.addAssembly('c:\myClasses.dll');
t = a.AssemblyHandle.GetType('MyLib.ClassA+eResults');
var = System.Activator.CreateInstance(t);
like image 199
Simon Mourier Avatar answered Feb 27 '23 13:02

Simon Mourier