I need to organize some simple security in a class depends on value of the enum. All that I can figure out is using attribute on a method and then run check then if it fails throw an exception. Sample:
[ModulePermission(PermissonFlags.Create)] public void CreateNew() { CheckPermission(); System.Windows.Forms.MessageBox.Show("Created!"); } protected void CheckPermission() { var method = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod(); if (!flags.HasFlag(method.GetCustomAttributes(true).Cast<ModulePermissionAttribute>().First().Flags)) { throw new ApplicationException("Access denied"); } } is there more elegant or simple way to do this, like just to trigger an event when method run?