在matlab代码中使用C#dll函数

时间:2014-07-15 09:19:05

标签: c# matlab .net-assembly

我有一个C#项目,我想在matlab中使用我的项目的功能。 我添加了

[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]

befor我的项目中的每个类,并制作输出类型类库。 但是当我在matlab中使用dll时,

temp = NET.addAssembly('../../foo')

然后foo.Classes,没有课! 我该怎么办?! PLZ帮帮我:)。

1 个答案:

答案 0 :(得分:3)

有关上述评论的示例

要使用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();
相关问题