-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSafeHandle.cs
86 lines (69 loc) · 1.68 KB
/
SafeHandle.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
75
76
77
78
79
80
81
82
83
84
85
86
using System;
namespace Com.Xenthrax.DllInjector
{
public abstract class SafeHandle : IDisposable
{
public abstract void Dispose();
public abstract IntPtr Value { get; }
public override string ToString()
{
return this.Value.ToString();
}
public string ToString(string format)
{
return this.Value.ToString(format);
}
public override int GetHashCode()
{
return this.Value.GetHashCode();
}
public override bool Equals(object obj)
{
return this == obj;
}
public static IntPtr operator -(SafeHandle value, int p)
{
return value.Value - p;
}
public static IntPtr operator -(SafeHandle value, long p)
{
return new IntPtr(value.Value.ToInt64() - p);
}
public static IntPtr operator -(SafeHandle value, IntPtr p)
{
return value - p.ToInt64();
}
public static IntPtr operator +(SafeHandle value, int p)
{
return value.Value + p;
}
public static IntPtr operator +(SafeHandle value, long p)
{
return new IntPtr(value.Value.ToInt64() + p);
}
public static IntPtr operator +(SafeHandle value, IntPtr p)
{
return value + p.ToInt64();
}
public static implicit operator IntPtr(SafeHandle value)
{
return value.Value;
}
public static explicit operator int(SafeHandle value)
{
return (int)value.Value;
}
public static explicit operator long(SafeHandle value)
{
return (long)value.Value;
}
public static bool operator ==(SafeHandle value1, IntPtr value2)
{
return value1.Value == value2;
}
public static bool operator !=(SafeHandle value1, IntPtr value2)
{
return value1.Value != value2;
}
}
}