MATLAB: Can I call hidden methods from a .NET Object through the Interface that it implements in MATLAB 7.13 (R2011b)

MATLAB

Suppose I have a .NET Assembly compiled from the following C# code:
namespace ClassLibrary1
{
public interface IClass
{
String myFunction(String s);
}
public class Class1 : IClass
{
String IClass.myFunction(String s)
{
return String.Format("Hello {0}", s);
}
}
}
As you can see I have used Implementation Hiding for myFunction. Or in other words in C# I CANNOT call myFunction as follows:
ClassLibrary1.Class1 obj = new ClassLibrary1.Class1();
obj.myFunction("World");
I can call myFunction through the IClass interface however:
((ClassLibrary1.IClass)obj).myFunction("World");
Can I also do this in MATLAB?

Best Answer

Because MATLAB is not a strongly typed language it is not possible to first cast the object instance to the interface. Using reflection, it is still possible to call the method through the interface though; the following code shows this:
%%Load Assembly
A = NET.addAssembly([pwd '\ClassLibrary1.dll']);
% Get Type information for the IClass interface
t = A.AssemblyHandle.GetType('ClassLibrary1.IClass');
%%Create an object instance
obj = ClassLibrary1.Class1;
%%Call the method (through reflection)
% First define an Object[] for the inputs
inputs = NET.createArray('System.Object',1);
% Define the actual inputs
inputs(1) = System.String('World');
% Call the method
t.InvokeMember('myFunction',System.Reflection.BindingFlags.InvokeMethod,[],obj,inputs)