gpt4 book ai didi

c# - 当位掩码(标志)枚举变得太大时该怎么办

转载 作者:IT王子 更新时间:2023-10-29 03:42:52 25 4
gpt4 key购买 nike

我在我的应用程序中有一组非常大的权限,我用 Flags 枚举表示。它正在快速接近长数据类型的实用上限。而且我被迫想出一个策略来尽快过渡到不同的结构。现在,我可以将这个列表分解成更小的部分,但是,根据我们的应用程序布局,这已经只是我们应用程序总体权限的一个子集。在管理权限时,我们将这种区别广泛用于显示目的,如果可以避免的话,我宁愿此时不必重新访问该代码。

还有其他人遇到过这个问题吗?你是怎么熬过来的?一般示例很好,但如果有任何我可以用来完成工作的特定语言技巧,我对特定于 c# 的示例最感兴趣。

可能不是必需的,但这是当前为我正在处理的应用程序部分定义的权限列表。

//Subgroup WebAgent
[Flags]
public enum WebAgentPermission : long
{
[DescriptionAttribute("View Rule Group")]
ViewRuleGroup = 1,
[DescriptionAttribute("Add Rule Group")]
AddRuleGroup = 2,
[DescriptionAttribute("Edit Rule Group")]
EditRuleGroup = 4,
[DescriptionAttribute("Delete Rule Group")]
DeleteRuleGroup = 8,
[DescriptionAttribute("View Rule")]
ViewRule = 16,
[DescriptionAttribute("Add Rule")]
AddRule = 32,
[DescriptionAttribute("Edit Rule")]
EditRule = 64,
[DescriptionAttribute("Delete Rule")]
DeleteRule = 128,
[DescriptionAttribute("View Location")]
ViewLocation = 256,
[DescriptionAttribute("Add Location")]
AddLocation = 512,
[DescriptionAttribute("Edit Location")]
EditLocation = 1024,
[DescriptionAttribute("Delete Location")]
DeleteLocation = 2048,
[DescriptionAttribute("View Volume Statistics")]
ViewVolumeStatistics = 4096,
[DescriptionAttribute("Edit Volume Statistics")]
EditVolumeStatistics = 8192,
[DescriptionAttribute("Upload Volume Statistics")]
UploadVolumeStatistics = 16384,
[DescriptionAttribute("View Role")]
ViewRole = 32768,
[DescriptionAttribute("Add Role")]
AddRole = 65536,
[DescriptionAttribute("Edit Role")]
EditRole = 131072,
[DescriptionAttribute("Delete Role")]
DeleteRole = 262144,
[DescriptionAttribute("View User")]
ViewUser = 524288,
[DescriptionAttribute("Add User")]
AddUser = 1048576,
[DescriptionAttribute("Edit User")]
EditUser = 2097152,
[DescriptionAttribute("Delete User")]
DeleteUser = 4194304,
[DescriptionAttribute("Assign Permissions To User")]
AssignPermissionsToUser = 8388608,
[DescriptionAttribute("Change User Password")]
ChangeUserPassword = 16777216,
[DescriptionAttribute("View Audit Logs")]
ViewAuditLogs = 33554432,
[DescriptionAttribute("View Team")]
ViewTeam = 67108864,
[DescriptionAttribute("Add Team")]
AddTeam = 134217728,
[DescriptionAttribute("Edit Team")]
EditTeam = 268435456,
[DescriptionAttribute("Delete Team")]
DeleteTeam = 536870912,
[DescriptionAttribute("View Web Agent Reports")]
ViewWebAgentReports = 1073741824,
[DescriptionAttribute("View All Locations")]
ViewAllLocations = 2147483648,
[DescriptionAttribute("Access to My Search")]
AccessToMySearch = 4294967296,
[DescriptionAttribute("Access to Pespective Search")]
AccessToPespectiveSearch = 8589934592,
[DescriptionAttribute("Add Pespective Search")]
AddPespectiveSearch = 17179869184,
[DescriptionAttribute("Edit Pespective Search")]
EditPespectiveSearch = 34359738368,
[DescriptionAttribute("Delete Pespective Search")]
DeletePespectiveSearch = 68719476736,
[DescriptionAttribute("Access to Search")]
AccessToSearch = 137438953472,
[DescriptionAttribute("View Form Roles")]
ViewFormRole = 274877906944,
[DescriptionAttribute("Add / Edit Form Roles")]
AddFormRole = 549755813888,
[DescriptionAttribute("Delete UserFormRolesDifferenceMasks")]
DeleteFormRole = 1099511627776,
[DescriptionAttribute("Export Locations")]
ExportLocations = 2199023255552,
[DescriptionAttribute("Import Locations")]
ImportLocations = 4398046511104,
[DescriptionAttribute("Manage Location Levels")]
ManageLocationLevels = 8796093022208,
[DescriptionAttribute("View Job Title")]
ViewJobTitle = 17592186044416,
[DescriptionAttribute("Add Job Title")]
AddJobTitle = 35184372088832,
[DescriptionAttribute("Edit Job Title")]
EditJobTitle = 70368744177664,
[DescriptionAttribute("Delete Job Title")]
DeleteJobTitle = 140737488355328,
[DescriptionAttribute("View Dictionary Manager")]
ViewDictionaryManager = 281474976710656,
[DescriptionAttribute("Add Dictionary Manager")]
AddDictionaryManager = 562949953421312,
[DescriptionAttribute("Edit Dictionary Manager")]
EditDictionaryManager = 1125899906842624,
[DescriptionAttribute("Delete Dictionary Manager")]
DeleteDictionaryManager = 2251799813685248,
[DescriptionAttribute("View Choice Manager")]
ViewChoiceManager = 4503599627370496,
[DescriptionAttribute("Add Choice Manager")]
AddChoiceManager = 9007199254740992,
[DescriptionAttribute("Edit Chioce Manager")]
EditChoiceManager = 18014398509481984,
[DescriptionAttribute("Delete Choice Manager")]
DeleteChoiceManager = 36028797018963968,
[DescriptionAttribute("Import Export Choices")] //57
ImportExportChoices = 72057594037927936
}

最佳答案

我在其中至少看到了一些不同枚举的值...

我的第一个想法是通过将权限拆分为逻辑组(RuleGroupPermissionsRulePermissionsLocationPermissions、... ),然后有一个类 (WebAgentPermissions) 为每个权限枚举类型公开一个属性。

由于权限值看起来是重复的,所以您最后可能只需要一个枚举就可以了:

[Flags]
public enum Permissions
{
View = 1,
Add = 2,
Edit = 4,
Delete = 8
}

然后让 WebAgentPermissions 类为要设置权限的每个区域公开一个属性;

class WebAgentPermissions
{
public Permissions RuleGroup { get; set; }
public Permissions Rule { get; set; }
public Permissions Location { get; set; }
// and so on...
}

关于c# - 当位掩码(标志)枚举变得太大时该怎么办,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1060760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com