在matlab代码中使用C#dll函数
我有一个C#项目,我想在matlab中使用我的项目的功能。 我补充说在matlab代码中使用C#dll函数,c#,matlab,.net-assembly,C#,Matlab,.net Assembly,我有一个C#项目,我想在matlab中使用我的项目的功能。 我补充说 [ClassInterface(ClassInterfaceType.AutoDual)] [ComVisible(true)] 在我的项目中的每个类之前,创建输出类型类库。 但是当我在matlab中使用dll时 temp = NET.addAssembly('../../foo') 然后foo.Classes,就没有课了! 我该怎么办?!请帮助我:)关于上述评论的示例 要使用NET.addAssembly(…)使用.NE
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
在我的项目中的每个类之前,创建输出类型类库。
但是当我在matlab中使用dll时
temp = NET.addAssembly('../../foo')
然后foo.Classes
,就没有课了!
我该怎么办?!请帮助我:)关于上述评论的示例
要使用NET.addAssembly(…)
使用.NET程序集中的类,无需使该类COM可见,但该类以及要访问的方法必须是公共的
.NET代码
namespace foo
{
public class SampleClass
{
// Constructor
public SampleClass() { }
// Static example
public static string StaticMethod() { return "Hello from static method."; }
// Instance example
public string InstanceMethod() { return "Hello from instance method."; }
}
}
来自Matlab的用法
% Loading the .NET assembly
NET.addAssembly('..\..\Foo.dll');
% Call of a static method
foo.SampleClass.StaticMethod()
% Call of an instance method
instance = foo.SampleClass();
instance.InstanceMethod();
使用
NET.addAssembly
不需要使类COM可见,但您的类至少需要是public
hmm,tnQ。但现在我无法访问的方法!好的,您想要访问的方法也必须是public
…请参阅我答案中的示例代码。