/// <summary> /// Returns the <see cref="Keyed.Flags.Enumeration{T}"/> <typeparamref name="T"/> Value /// by its <paramref name="bytes"/>. <paramref name="_"/> is provided to connect the /// caller with the <see cref="Keyed.Flags.Enumeration{T}"/> <typeparamref name="T"/>, /// nothing more, nothing less. /// </summary> /// <param name="_">Given an anchor value identifying the Type <typeparamref name="T"/>.</param> /// <param name="bytes">The Bytes correlating to the <see cref="ImmutableBitArray"/>.</param> /// <returns></returns> /// <see cref="ImmutableBitArray"/> /// <see cref="Keyed.Flags.Enumeration{T}.FromBitArray"/> public static T GetValueByBytes <T>(this T _, byte[] bytes) where T : Keyed.Flags.Enumeration <T> { var key = new ImmutableBitArray(bytes); var value = Keyed.Flags.Enumeration <T> .FromBitArray(key).AssertNotNull(); value.Key.AssertNotNull().AssertEqual(key); return(value); }
/// <inheritdoc /> public bool Equals(ImmutableBitArray other) => other != null && Equals(_bytes, other._bytes);
/// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static bool Equals(ImmutableBitArray a, ImmutableBitArray b) => Equals(a?._bytes, b?._bytes);
/// <inheritdoc /> public int CompareTo(ImmutableBitArray other) => CompareTo(_bytes, other?._bytes);
/// <summary> /// /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int CompareTo(ImmutableBitArray a, ImmutableBitArray b) => CompareTo(a?._bytes, b?._bytes);
/// <summary> /// Performs the Bitwise Exclusive Or operation on the current instance, /// <paramref name="other"/>, and <paramref name="others"/> instances. Returns a new /// instance containing the result. /// </summary> /// <param name="other"></param> /// <param name="others"></param> /// <returns>A new instance containing the result.</returns> public ImmutableBitArray Xor(ImmutableBitArray other , params ImmutableBitArray[] others) => Xor(GetRange(other).Concat(others).ToArray());
/// <inheritdoc /> public ImmutableBitArray Xor(ImmutableBitArray other) => Xor(GetRange(other));
/// <inheritdoc /> public ImmutableBitArray And(ImmutableBitArray other) => And(GetRange(other));
/// <summary> /// Returns a hexadecimal representation of the <paramref name="arr"/> in the usual MSB /// order. /// </summary> /// <param name="arr"></param> /// <param name="msb">Returns the string in <paramref name="msb"/> order. Default is true /// consistent with <see cref="ImmutableBitArray.ToBytes"/>.</param> /// <returns></returns> public static string ToByteString(this ImmutableBitArray arr, bool msb = true) { // Return in the appropriate order. return((arr == null ? new byte[0] : arr.ToBytes(msb)).ToByteString()); }