public void SetPermission(Permissions permission, bool hasPermission) { if (permission == Permissions.None) { return; } byte byteIndex = (byte)((int)permission / 8); byte bitIndex = (byte)((int)permission % 8); byte mask = (byte)Bit.LeftShift(1, bitIndex); if (hasPermission) { RawPermissionField[byteIndex] = Bit.SetBit(mask, RawPermissionField[byteIndex]); } else { RawPermissionField[byteIndex] = Bit.ClearBit(mask, RawPermissionField[byteIndex]); } }
private static byte[] GetPermissionBytes(Permissions[] permissions) { byte[] result = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 }; if (permissions != null) { foreach (Permissions permission in permissions) { if (permission == Permissions.None) { continue; } byte byteIndex = (byte)((int)permission / 8); byte bitIndex = (byte)((int)permission % 8); byte mask = (byte)Bit.LeftShift(1, bitIndex); result[byteIndex] = Bit.SetBit(mask, result[byteIndex]); } } return(result); }