c# - 使用像属性参数一样的枚举项名称

标签 c# .net wcf-ria-services

我只想不要为每个属性使用“Managers”并为此使用一些枚举。

但似乎是不可能的还是我错了?

所以我尝试替换

[RequiresRole("Managers")]

[RequiresRole(HardCodedRoles.Managers.ToString())]

...

public enum HardCodedRoles
{ 
            Administrators,
            Managers
}

最佳答案

用一个类而不是一个枚举怎么样,使类成为静态的以避免有人 new:ing 它?

public static class HardCodedRoles
{
    public const string Managers = "Managers";
    public const string Administrators = "Administrators";
}

[RequiresRole(HardCodedRoles.Managers)] 

关于c# - 使用像属性参数一样的枚举项名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12182578/

相关文章:

asp.net - 如何将非数据库属性添加到 Entity Framework 实体?

entity-framework - 无法使用 RIA 服务在客户端上加载相关实体

c# - 仅在依赖属性更改值后引发事件

c# - BinaryReader 的奇怪行为

c# - 如何在 WPF 4.5 中实现 INotifyDataErrorInfo?

c# - 试图在 IList 中获取索引位置的问题

.net - "win-x86"或 "win-x64"任何 CPU 的目标运行时?

.net - 提供参数时 SOAP 请求失败

silverlight - RIA 服务调用操作返回具有实体属性的复杂类型

c# - 计算字符串中的制表符数