C# enums are much simpler types than Java enums - they cannot have constructors, methods, or member fields. However, you can achieve similar functionality using a class with static instances that represent each "enumeration."
public sealed class Module
{
public static Module None { get; } = new Module(SubModule.None);
public static Module Authentication { get; } = new Module(SubModule.Login);
public static Module User { get; } = new Module(SubModule.User, SubModule.ForgotPassword, SubModule.ResetPassword);
private SubModule[] _subModules;
private Module(params SubModule[] subModules)
{
_subModules = subModules;
}
}
This class allows you to access the static Module
instances using basically the same syntax as an enumeration, and the private constructor prevents new instances from being created.
Note that SubModule
could be a true C# enum
if that suits your needs, or it could also be a class with static properties for "enum" values.