-
Notifications
You must be signed in to change notification settings - Fork 18
/
Extension.cs
74 lines (69 loc) · 2.27 KB
/
Extension.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Windows;
namespace InfiniteRuntimeTagViewer
{
public static class Extension
{
/// <summary>
/// Gets the window left.
/// </summary>
/// <param name="window">The window.</param>
/// <returns></returns>
public static double GetWindowLeft(this Window window)
{
if (window.WindowState == WindowState.Maximized)
{
System.Reflection.FieldInfo? leftField = typeof(Window).GetField("_actualLeft", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
return (double) leftField.GetValue(window);
}
else
{
return window.Left;
}
}
/// <summary>
/// Gets the window top.
/// </summary>
/// <param name="window">The window.</param>
/// <returns></returns>
public static double GetWindowTop(this Window window)
{
if (window.WindowState == WindowState.Maximized)
{
System.Reflection.FieldInfo? topField = typeof(Window).GetField("_actualTop", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
return (double) topField.GetValue(window);
}
else
{
return window.Top;
}
}
public static bool GetBit(this byte b, int bitNumber)
{
return (b & (1 << bitNumber)) != 0;
}
public static void UpdateBit(ref this byte aByte, int pos, bool value)
{
if (value)
{
//left-shift 1, then bitwise OR
aByte = (byte) (aByte | (1 << pos));
}
else
{
//left-shift 1, then take complement, then bitwise AND
aByte = (byte) (aByte & ~(1 << pos));
}
}
// public static byte SetBit(this byte target, int field, bool value)
// {
// if (value) //set value
// {
// return (byte) (target | field);
// }
// else //clear value
// {
// return (byte) (target & (~field));
// }
// }
}
}