一种简单的直观的高效的权限设计
2010-09-30 22:41:33 来源:WEB开发网使用一下:
1 //创建一个用户
2 User admin = new User();
3 PermissionTypes permissions = new PermissionTypes();
4 admin.Permissions = permissions;
5 //添加权限
6 admin.Permissions = admin.Permissions.Add(PermissionTypes.Create);
7 admin.Permissions = admin.Permissions.Add(PermissionTypes.Read);
8 admin.Permissions = admin.Permissions.Add(PermissionTypes.Write);
9 //判断权限
10 bool canRead = admin.Permissions.Has(PermissionTypes.Read); //true
11 bool canWrite = admin.Permissions.Has(PermissionTypes.Write); //true
12 bool canDelete = admin.Permissions.Has(PermissionTypes.Delete); //false
13 bool canCreate = admin.Permissions.Has(PermissionTypes.Create); //true
14
15 Console.WriteLine(canRead); //true
16 Console.WriteLine(canWrite); //true
17 Console.WriteLine(canDelete); //false
18 Console.WriteLine(canCreate); //true
19 Console.Read();
更多精彩
赞助商链接