/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
namespace dnSpy.Contracts.Hex.Files {
///
/// Flag info
///
public readonly struct FlagInfo {
const ulong EnumNameValue = ulong.MaxValue;
///
/// Name
///
public string Name { get; }
///
/// Mask
///
public ulong Mask { get; }
///
/// Value
///
public ulong Value { get; }
///
/// true if it only stores the name of the enum and the enum mask. is not used
/// and should be ignored.
///
public bool IsEnumName => (Value & ~Mask) != 0 && Value == EnumNameValue;
///
/// Creates an instance that only holds the name of the embedded enum value
///
/// Enum mask
/// Name of enum
///
public static FlagInfo CreateEnumName(ulong mask, string name) => new FlagInfo(mask, name, false);
FlagInfo(ulong mask, string name, bool dummy) {
if (mask == 0)
throw new ArgumentOutOfRangeException(nameof(mask));
Name = name ?? throw new ArgumentNullException(nameof(name));
Mask = mask;
Value = EnumNameValue;
}
///
/// Constructor
///
/// Bit mask
/// Name
public FlagInfo(ulong bitMask, string name)
: this(bitMask, bitMask, name) {
}
///
/// Constructor
///
/// Mask
/// Value
/// Name
public FlagInfo(ulong mask, ulong value, string name) {
if (mask == 0)
throw new ArgumentOutOfRangeException(nameof(mask));
if ((value & ~mask) != 0)
throw new ArgumentOutOfRangeException(nameof(value));
Name = name ?? throw new ArgumentNullException(nameof(name));
Mask = mask;
Value = value;
}
}
}