Changed to BitHelper broke too much so reverted.

pull/83/head
David Hall 2019-07-16 07:43:10 -06:00
parent 6eb0aa354d
commit ceff4504f0
3 changed files with 23 additions and 22 deletions

View File

@ -12,7 +12,7 @@ namespace Vanara.Extensions
/// <param name="bits">The bit vector.</param>
/// <param name="idx">The zero-based index of the bit to get.</param>
/// <returns><see langword="true"/> if the bit is set (1); <see langword="false"/> otherwise.</returns>
public static bool GetBit<T>(this T bits, byte idx) where T : struct, IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable =>
public static bool GetBit<T>(T bits, byte idx) where T : struct, IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable =>
(idx < (Marshal.SizeOf(typeof(T)) * 8)) ? (bits.ToInt64(null) & 1 << idx) != 0 : throw new ArgumentOutOfRangeException(nameof(idx));
/// <summary>Gets the bit array value from the specified range in a bit vector.</summary>
@ -21,7 +21,7 @@ namespace Vanara.Extensions
/// <param name="startIdx">The zero-based start index of the bit range to get.</param>
/// <param name="count">The number of sequential bits to fetch starting at <paramref name="startIdx"/>.</param>
/// <returns>The value of the requested bit range.</returns>
public static T GetBits<T>(this T bits, byte startIdx, byte count) where T : struct, IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
public static T GetBits<T>(T bits, byte startIdx, byte count) where T : struct, IComparable, IComparable<T>, IConvertible, IEquatable<T>, IFormattable
{
if (startIdx >= (Marshal.SizeOf(typeof(T)) * 8)) throw new ArgumentOutOfRangeException(nameof(startIdx));
if (count + startIdx > (Marshal.SizeOf(typeof(T)) * 8)) throw new ArgumentOutOfRangeException(nameof(count));

View File

@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.Extensions;
using Vanara.InteropServices;
using static Vanara.Extensions.BitHelper;
namespace Vanara.PInvoke
{
@ -1617,10 +1617,10 @@ namespace Vanara.PInvoke
public UIntPtr Flags;
/// <summary>If <see langword="true"/>, the page is sharable; otherwise, the page is not sharable.</summary>
public bool Shared => Flags.ToUInt32().GetBit(9);
public bool Shared => GetBit(Flags.ToUInt32(), 9);
/// <summary>The number of processes that share this page. The maximum value of this member is 7.</summary>
public uint ShareCount => Flags.ToUInt32().GetBits(5, 3);
public uint ShareCount => GetBits(Flags.ToUInt32(), 5, 3);
/// <summary>
/// <para>The protection attributes of the page. This member can be one of the following values.</para>
@ -1759,7 +1759,7 @@ namespace Vanara.PInvoke
/// </item>
/// </list>
/// </summary>
public uint Protection => Flags.ToUInt32().GetBits(0, 5);
public uint Protection => GetBits(Flags.ToUInt32(), 0, 5);
public IntPtr VirtualPage => new IntPtr((long)Flags.ToUInt64() & ~0xFFFL);
}
@ -1775,19 +1775,19 @@ namespace Vanara.PInvoke
public UIntPtr Flags;
/// <summary>If <see langword="true"/>, the page is valid; otherwise, the page is not valid.</summary>
public bool Valid => Flags.ToUInt32().GetBit(0);
public bool Valid => GetBit(Flags.ToUInt32(), 0);
public bool Locked => Valid ? Flags.ToUInt32().GetBit(22) : false;
public bool Locked => Valid ? GetBit(Flags.ToUInt32(), 22) : false;
public bool LargePage => Valid ? Flags.ToUInt32().GetBit(23) : false;
public bool LargePage => Valid ? GetBit(Flags.ToUInt32(), 23) : false;
public bool Bad => Flags.ToUInt32().GetBit(31);
public bool Bad => GetBit(Flags.ToUInt32(), 31);
/// <summary>If <see langword="true"/>, the page is sharable; otherwise, the page is not sharable.</summary>
public bool Shared => Flags.ToUInt32().GetBit(15);
public bool Shared => GetBit(Flags.ToUInt32(), 15);
/// <summary>The number of processes that share this page. The maximum value of this member is 7.</summary>
public uint ShareCount => Valid ? Flags.ToUInt32().GetBits(1, 3) : 0U;
public uint ShareCount => Valid ? GetBits(Flags.ToUInt32(), 1, 3) : 0U;
/// <summary>
/// <para>The protection attributes of the page. This member can be one of the following values.</para>
@ -1926,9 +1926,9 @@ namespace Vanara.PInvoke
/// </item>
/// </list>
/// </summary>
public uint Protection => Valid ? Flags.ToUInt32().GetBits(4, 11) : 0U;
public uint Protection => Valid ? GetBits(Flags.ToUInt32(), 4, 11) : 0U;
public uint Node => Valid ? Flags.ToUInt32().GetBits(0, 5) : 0U;
public uint Node => Valid ? GetBits(Flags.ToUInt32(), 0, 5) : 0U;
}
/// <summary>Contains working set information for a process.</summary>

View File

@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using static Vanara.Extensions.BitHelper;
namespace Vanara.PInvoke
{
@ -732,36 +733,36 @@ namespace Vanara.PInvoke
/// <summary>
/// <para>The type of segment. This member can be one of the following values:</para>
/// </summary>
public byte Type { get => (byte)Flags.GetBits(0, 5); set => BitHelper.SetBits(ref Flags, 0, 5, value); }
public byte Type { get => GetBits((byte)Flags, 0, 5); set => SetBits(ref Flags, 0, 5, value); }
/// <summary>
/// <para>
/// The privilege level of the descriptor. This member is an integer value in the range 0 (most privileged) through 3 (least privileged).
/// </para>
/// </summary>
public byte Dpl { get => (byte)Flags.GetBits(5, 2); set => BitHelper.SetBits(ref Flags, 5, 2, value); }
public byte Dpl { get => GetBits((byte)Flags, 5, 2); set => SetBits(ref Flags, 5, 2, value); }
/// <summary>
/// <para>The present flag. This member is 1 if the segment is present in physical memory or 0 if it is not.</para>
/// </summary>
public bool Pres { get => Flags.GetBit(7); set => BitHelper.SetBit(ref Flags, 7, value); }
public bool Pres { get => GetBit(Flags, 7); set => SetBit(ref Flags, 7, value); }
/// <summary>
/// <para>The high bits (16–19) of the address of the last byte in the segment.</para>
/// </summary>
public byte LimitHi { get => (byte)Flags.GetBits(8, 4); set => BitHelper.SetBits(ref Flags, 8, 4, value); }
public byte LimitHi { get => GetBits((byte)Flags, 8, 4); set => SetBits(ref Flags, 8, 4, value); }
/// <summary>
/// <para>
/// The space that is available to system programmers. This member might be used for marking segments in some system-specific way.
/// </para>
/// </summary>
public bool Sys { get => Flags.GetBit(12); set => BitHelper.SetBit(ref Flags, 12, value); }
public bool Sys { get => GetBit(Flags, 12); set => SetBit(ref Flags, 12, value); }
/// <summary>
/// <para>Reserved.</para>
/// </summary>
public bool Reserved_0 { get => Flags.GetBit(13); set => BitHelper.SetBit(ref Flags, 13, value); }
public bool Reserved_0 { get => GetBit(Flags, 13); set => SetBit(ref Flags, 13, value); }
/// <summary>
/// <para>
@ -772,12 +773,12 @@ namespace Vanara.PInvoke
/// If the segment is a code segment, this member contains 1. The segment runs with the default (native mode) instruction set.
/// </para>
/// </summary>
public bool Default_Big { get => Flags.GetBit(14); set => BitHelper.SetBit(ref Flags, 14, value); }
public bool Default_Big { get => GetBit(Flags, 14); set => SetBit(ref Flags, 14, value); }
/// <summary>
/// <para>The granularity. This member contains 0 if the segment is byte granular, 1 if the segment is page granular.</para>
/// </summary>
public bool Granularity { get => Flags.GetBit(15); set => BitHelper.SetBit(ref Flags, 15, value); }
public bool Granularity { get => GetBit(Flags, 15); set => SetBit(ref Flags, 15, value); }
}
/// <summary>Used by thread context functions.</summary>