我有这种情况,用户有自己的角色
普通用户
托管
财务
托管人和财务都是超级用户
我如何检查角色保管人是否是超级用户
这是我的示例代码..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
public enum Role
{
NormalUser = 0,
Custodian = 1,
Finance = 2,
SuperUser = Custodian | Finance,
All = Custodian | Finance | NormalUser
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Normal: " + Convert.ToInt32(Role.NormalUser));
Console.WriteLine("Custodian: " + Convert.ToInt32(Role.Custodian));
Console.WriteLine("Finance: " + Convert.ToInt32(Role.Finance));
Console.WriteLine("SuperUser: " + Convert.ToInt32(Role.SuperUser));
Console.WriteLine("All: " + Convert.ToInt32(Role.All));
Console.WriteLine();
Console.WriteLine("Normal User is in All: {0}", Role.NormalUser == Role.All);
Console.WriteLine("Normal User is not a SuperUser: {0}", Role.NormalUser != Role.SuperUser);
Console.WriteLine("Normal User is not a Custodian: {0}", Role.NormalUser != Role.Custodian);
Console.WriteLine();
Console.WriteLine("Custodian is in All: {0}", Role.Custodian == Role.All);
Console.WriteLine("Custodian is a SuperUser: {0}", Role.Custodian == Role.SuperUser);
Console.WriteLine("Custodian is a NormalUser: {0}", Role.Custodian == Role.NormalUser);
Console.WriteLine();
Console.WriteLine("Finance is in All: {0}", Role.Finance == Role.All);
Console.WriteLine("Finance is a SuperUser: {0}", Role.Finance == Role.SuperUser);
Console.WriteLine("Finance is a NormalUser: {0}", Role.Finance == Role.NormalUser);
Console.ReadLine();
}
}
}
如果我们运行它,这就是结果
Normal: 0
Custodian: 1
Finance: 2
SuperUser: 3
All: 3
Normal User is in All: False
Normal User is not a SuperUser: True
Normal User is not a Custodian: True
Custodian is in All: False
Custodian is a SuperUser: False
Custodian is a NormalUser: False
Finance is in All: False
Finance is a SuperUser: False
Finance is a NormalUser: False
我期待一个
保管人在所有:真,
保管人是超级用户:真,
财务在所有:真,
财务是超级用户:真,
普通用户在所有:真