How can I display all the enumerations in my .NET assembly?

9 次查看(过去 30 天)

I'm distributing a .NET software library for use in MATLAB. In the assembly (DLL file), I define certain enumerations inside my classes. How can I display all the enumerations in my assembly?

采纳的回答

MathWorks Support Team
You can use the NET.addAssembly function to read basic information about an assembly.   NET.addAssembly returns a NET.addAssembly object, which contains the names of the members of the assembly, including enumerations.
The steps below show how you can use the NET.addAssembly object to display the .NET Enumerations (enums) in your assembly. 
 
1. Load the .NET Assembly
asmInfo = NET.addAssembly('<Full path to your assembly>');
2. Retrieve a cell array of all enums defined in the loaded assembly
asmEnums = asmInfo.Enums;
3. Iterate through the enums. For each enums, obtain its .NET Type information and print all possible values (literals) for each enums
for enumIdx = 1:numel(asmEnums) % Get the num Type enumType = asmInfo.AssemblyHandle.GetType(asmEnums{enumIdx}); % Print the enum name fprintf('Enum Literals for Enum: %s\n', asmEnums{enumIdx}); % Create an array of names using the GetNames method: allNames = System.Enum.GetNames(enumType); % Print all the literals in the enum for idx = 1:allNames.Length disp(allNames(idx)) end end
For related information see:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Microsoft .NET 的更多信息

产品


版本

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by