How to call C# ENUM with values whose name start with underscore?
Show older comments
I like to call a C# function in MATLAB.
The C# function has ENUM with values whose names start with underscores.
And a function which accepts the Enum as argument, something like this--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace firstdotnet
{
public enum RF_Amp_Atten_Step
{
_3dB = 8,
_9dB = 17,
_12dB = 18,
_15dB = 19,
_6dB = 28,
aa = 25,
abc_ = 30,
Full_Core = 56,
}
public class fistclass
{
public int callmylib(RF_Amp_Atten_Step e)
{
return (int)e;
}
}
}
Now, to call this function in MATLAB, I compile this program into assembly, and using Net.addAssembly and call assembly's function.
asm = NET.addAssembly('<FullPathToAssembly>\firstdotnet.dll');
cls = firstdotnet.fistclass;
If I use Enum's value whose name start with letter, then it works fine-
res = callmylib(cls, firstdotnet.RF_Amp_Atten_Step.Full_Core);
But, when calling the function with Enum's value whose name start with underscore gives error- ERROR: res = callmylib(cls, firstdotnet.RF_Amp_Atten_Step._12dB); ↑ Error: Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
I know that a valid variable name in MATLAB can only start with a letter, followed by letters, digits, or underscores.
And, the Enum that we are passing to function is a MATLAB struct which cannot have invalid variable names.
But, is there a way I can use those Enum values?
I cannot modify my C# code.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Compiler SDK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!