Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public class Program
- {
- public static void Main()
- {
- }
- public class BasePermissions
- {
- public int Permission {get;set;}
- }
- public class DivisionsPermissions : BasePermissions
- {
- public enum Permissions
- {
- Create = 1, Read = 2, Update = 4, Delete = 8, Custom = 16
- }
- public Dictionary<Permissions, bool> GetPermissions()
- {
- return new Dictionary<Permissions, bool>
- {
- {Permissions.Create, (Permission & (int)Permissions.Create)==(int)Permissions.Create},
- {Permissions.Read, (Permission & (int)Permissions.Read)==(int)Permissions.Read},
- {Permissions.Update, (Permission & (int)Permissions.Update)==(int)Permissions.Update},
- {Permissions.Delete, (Permission & (int)Permissions.Delete)==(int)Permissions.Delete},
- {Permissions.Custom, (Permission & (int)Permissions.Custom)==(int)Permissions.Custom}
- };
- }
- public bool GetPermission(Permissions permission)
- {
- return GetPermissions()[permission];
- }
- public void SetPermission(Permissions permission, bool value)
- {
- //bitwise NOT ~
- // NOT permission if value is false
- // then and with Permission property
- //if value true OR with property
- //if value false NOT permission the OR with Permission Property
- var perm = (int)permission;
- if (!value)
- perm = ~perm;
- Permission |= (int)perm;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement