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

10 views (last 30 days)

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?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Jun 2025
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:

More Answers (0)

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!