Matlab中的C#Enum类型
我正在使用MatlabR2010B,在C#下有一个枚举: 在一个方法中,我有一个参数,它是一种格式:Matlab中的C#Enum类型,c#,matlab,enums,C#,Matlab,Enums,我正在使用MatlabR2010B,在C#下有一个枚举: 在一个方法中,我有一个参数,它是一种格式: public void MyMethod(MyFormat format, double number) { .... } 然后我使用Matlab,我想使用MyMethod。以下是标准方式的代码: >>format = MyNamespace.MyFormat.value1; >>MyNamespace.MyMethod(format, 15); 当我尝试将“多
public void MyMethod(MyFormat format, double number)
{
....
}
然后我使用Matlab,我想使用MyMethod。以下是标准方式的代码:
>>format = MyNamespace.MyFormat.value1;
>>MyNamespace.MyMethod(format, 15);
当我尝试将“多值”作为MyFormat传递时会出现问题:
>>format = MyNamespace.MyFormat.value1 | MyNamespace.MyFormat.value2;
>>MyNamespace.MyMethod(format, 15);
我找到了一个简单的解决方案,但它需要更新版本的MatlabR2011A。另一个解决方案是在Matlab中实现此功能:
function enum = EnumParse(typename, value)
type = System.Type.GetType(typename);
values = regexp(value, ', ', 'split');
enum = cell(1, length(values));
for i = 1:length(values)
enum{i} = System.Enum.Parse(type, values{i});
end
end
但是,行System.Type.GetType('MyNamespace.MyFormat')返回空值,而对于类型System.Type.GetType('System.String')则不是空值
我的问题是如何将多个值解析为一个枚举?
谢谢 使用MatLab,因为它是Enum.Parse,以任意多个重载为例
类型、值、值…?似乎不表示您正在分析多个值,例如enum.Parse(类型、字符串、布尔值)。'您为MatlabR2011A找到的简单解决方案是什么?请告诉我,有趣的是,在R2011a版本的Matlab中找到的简单解决方案是使用新函数bitor,它直接作用于位,就像在C#中一样。。你可以在mathworks和R2011a文档中找到它谢谢你,但是我应该提到我不能在C代码上工作,我只能在Matlab下编码……很抱歉我没有意识到这一点
function enum = EnumParse(typename, value)
type = System.Type.GetType(typename);
values = regexp(value, ', ', 'split');
enum = cell(1, length(values));
for i = 1:length(values)
enum{i} = System.Enum.Parse(type, values{i});
end
end