/
ZipEntryExtensions.cs
32 lines (30 loc) · 1.04 KB
/
ZipEntryExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;
using System.Text;
namespace ICSharpCode.SharpZipLib.Zip
{
/// <summary>
/// General ZipEntry helper extensions
/// </summary>
public static class ZipEntryExtensions
{
/// <summary>
/// Efficiently check if a <see cref="GeneralBitFlags">flag</see> is set without enum un-/boxing
/// </summary>
/// <param name="entry"></param>
/// <param name="flag"></param>
/// <returns>Returns whether the flag was set</returns>
public static bool HasFlag(this ZipEntry entry, GeneralBitFlags flag)
=> (entry.Flags & (int) flag) != 0;
/// <summary>
/// Efficiently set a <see cref="GeneralBitFlags">flag</see> without enum un-/boxing
/// </summary>
/// <param name="entry"></param>
/// <param name="flag"></param>
/// <param name="enabled">Whether the passed flag should be set (1) or cleared (0)</param>
public static void SetFlag(this ZipEntry entry, GeneralBitFlags flag, bool enabled = true)
=> entry.Flags = enabled
? entry.Flags | (int) flag
: entry.Flags & ~(int) flag;
}
}