我一直很享受使用Matlab .NET Interface在Matlab中使用.NET类型的能力。
我正在尝试使用一组Matlab包装来公开.NET API(包装以使API感觉“Matlab-y”)。我发现自己一遍又一遍地做的事情之一就是在Matlab中创建静态辅助方法,将DTO从.NET实体转换为Matlab结构或类。
有没有人知道类似AutoMapper的工具来帮助这种映射?
编辑:
这是一个例子。在C#库中:
namespace MyLib { public class MyClass { public string MyString { get; set; } public int MyInt { get; set; } public MyClass(string myString, int myInt) { MyString = myString; MyInt = myInt; } } }
然后,在Matlab中:
NET.addAssembly('MyLib.dll'); % create an instance of my .NET type netObject = MyLib.MyClass('high', 5); % map that instance to values in a Matlab struct % since Matlab's dynamic, create the struct on the fly matlabStruct = map(netObject); % assert that the values have been mapped correctly assert(isstruct(matlabStruct)); assert(isfield(matlabStruct, 'MyString')); assert(isfield(matlabStruct, 'MyInt')); assert(matlabStruct.MyString == 'high'); assert(matlabStruct.MyInt == 5); % equivalent code w/o mapper: matlabStruct.MyString = char(netObject.MyString); matlabStruct.MyInt = int32(netObject.MyInt);