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 inNo 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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With