mscorlib(4.0.0.0) API with additions
UIntPtr.cs
5 using System.Security;
6 
7 namespace System
8 {
10  [Serializable]
11  [CLSCompliant(false)]
12  [ComVisible(true)]
13  [__DynamicallyInvokable]
14  public struct UIntPtr : ISerializable
15  {
16  [SecurityCritical]
17  private unsafe void* m_value;
18 
20  public static readonly UIntPtr Zero;
21 
24  [__DynamicallyInvokable]
25  public static int Size
26  {
27  [NonVersionable]
28  [__DynamicallyInvokable]
29  get
30  {
31  return 8;
32  }
33  }
34 
37  [SecuritySafeCritical]
38  [NonVersionable]
39  [__DynamicallyInvokable]
40  public unsafe UIntPtr(uint value)
41  {
42  m_value = (void*)value;
43  }
44 
48  [SecuritySafeCritical]
49  [NonVersionable]
50  [__DynamicallyInvokable]
51  public unsafe UIntPtr(ulong value)
52  {
53  m_value = (void*)value;
54  }
55 
58  [SecurityCritical]
59  [CLSCompliant(false)]
60  [NonVersionable]
61  public unsafe UIntPtr(void* value)
62  {
63  m_value = value;
64  }
65 
66  [SecurityCritical]
67  private unsafe UIntPtr(SerializationInfo info, StreamingContext context)
68  {
69  ulong uInt = info.GetUInt64("value");
70  if (Size == 4 && uInt > uint.MaxValue)
71  {
72  throw new ArgumentException(Environment.GetResourceString("Serialization_InvalidPtrValue"));
73  }
74  m_value = (void*)uInt;
75  }
76 
82  [SecurityCritical]
84  {
85  if (info == null)
86  {
87  throw new ArgumentNullException("info");
88  }
89  info.AddValue("value", (ulong)m_value);
90  }
91 
96  [SecuritySafeCritical]
97  [__DynamicallyInvokable]
98  public unsafe override bool Equals(object obj)
99  {
100  if (obj is UIntPtr)
101  {
102  return m_value == ((UIntPtr)obj).m_value;
103  }
104  return false;
105  }
106 
109  [SecuritySafeCritical]
110  [__DynamicallyInvokable]
111  public unsafe override int GetHashCode()
112  {
113  return (int)m_value & int.MaxValue;
114  }
115 
119  [SecuritySafeCritical]
120  [NonVersionable]
121  [__DynamicallyInvokable]
122  public unsafe uint ToUInt32()
123  {
124  return checked((uint)m_value);
125  }
126 
129  [SecuritySafeCritical]
130  [NonVersionable]
131  [__DynamicallyInvokable]
132  public unsafe ulong ToUInt64()
133  {
134  return (ulong)m_value;
135  }
136 
139  [SecuritySafeCritical]
140  [__DynamicallyInvokable]
141  public unsafe override string ToString()
142  {
143  return ((ulong*)(&m_value))->ToString(CultureInfo.InvariantCulture);
144  }
145 
149  [NonVersionable]
150  public static explicit operator UIntPtr(uint value)
151  {
152  return new UIntPtr(value);
153  }
154 
159  [NonVersionable]
160  public static explicit operator UIntPtr(ulong value)
161  {
162  return new UIntPtr(value);
163  }
164 
169  [SecuritySafeCritical]
170  [NonVersionable]
171  public unsafe static explicit operator uint(UIntPtr value)
172  {
173  return checked((uint)value.m_value);
174  }
175 
179  [SecuritySafeCritical]
180  [NonVersionable]
181  public unsafe static explicit operator ulong(UIntPtr value)
182  {
183  return (ulong)value.m_value;
184  }
185 
189  [SecurityCritical]
190  [CLSCompliant(false)]
191  [NonVersionable]
192  public unsafe static explicit operator UIntPtr(void* value)
193  {
194  return new UIntPtr(value);
195  }
196 
200  [SecurityCritical]
201  [CLSCompliant(false)]
202  [NonVersionable]
203  public unsafe static explicit operator void*(UIntPtr value)
204  {
205  return value.m_value;
206  }
207 
213  [SecuritySafeCritical]
214  [NonVersionable]
215  [__DynamicallyInvokable]
216  public unsafe static bool operator ==(UIntPtr value1, UIntPtr value2)
217  {
218  return value1.m_value == value2.m_value;
219  }
220 
226  [SecuritySafeCritical]
227  [NonVersionable]
228  [__DynamicallyInvokable]
229  public unsafe static bool operator !=(UIntPtr value1, UIntPtr value2)
230  {
231  return value1.m_value != value2.m_value;
232  }
233 
238  [NonVersionable]
239  public static UIntPtr Add(UIntPtr pointer, int offset)
240  {
241  return pointer + offset;
242  }
243 
248  [NonVersionable]
249  public static UIntPtr operator +(UIntPtr pointer, int offset)
250  {
251  return new UIntPtr((ulong)((long)pointer.ToUInt64() + (long)offset));
252  }
253 
258  [NonVersionable]
259  public static UIntPtr Subtract(UIntPtr pointer, int offset)
260  {
261  return pointer - offset;
262  }
263 
268  [NonVersionable]
269  public static UIntPtr operator -(UIntPtr pointer, int offset)
270  {
271  return new UIntPtr((ulong)((long)pointer.ToUInt64() - (long)offset));
272  }
273 
276  [SecuritySafeCritical]
277  [CLSCompliant(false)]
278  [NonVersionable]
279  public unsafe void* ToPointer()
280  {
281  return m_value;
282  }
283  }
284 }
A platform-specific type that is used to represent a pointer or a handle.
Definition: UIntPtr.cs:14
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe UIntPtr(void *value)
Initializes a new instance of T:System.UIntPtr using the specified pointer to an unspecified type.
Definition: UIntPtr.cs:61
unsafe uint ToUInt32()
Converts the value of this instance to a 32-bit unsigned integer.
Definition: UIntPtr.cs:122
Definition: __Canon.cs:3
unsafe UIntPtr(uint value)
Initializes a new instance of the T:System.UIntPtr structure using the specified 32-bit pointer or ha...
Definition: UIntPtr.cs:40
Describes the source and destination of a given serialized stream, and provides an additional caller-...
unsafe UIntPtr(ulong value)
Initializes a new instance of T:System.UIntPtr using the specified 64-bit pointer or handle.
Definition: UIntPtr.cs:51
static UIntPtr operator+(UIntPtr pointer, int offset)
Adds an offset to the value of an unsigned pointer.
Definition: UIntPtr.cs:249
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
unsafe override bool Equals(object obj)
Returns a value indicating whether this instance is equal to a specified object.
Definition: UIntPtr.cs:98
unsafe override string ToString()
Converts the numeric value of this instance to its equivalent string representation.
Definition: UIntPtr.cs:141
static int Size
Gets the size of this instance.
Definition: UIntPtr.cs:26
static UIntPtr Add(UIntPtr pointer, int offset)
Adds an offset to the value of an unsigned pointer.
Definition: UIntPtr.cs:239
unsafe override int GetHashCode()
Returns the hash code for this instance.
Definition: UIntPtr.cs:111
static unsafe bool operator !=(UIntPtr value1, UIntPtr value2)
Determines whether two specified instances of T:System.UIntPtr are not equal.
Definition: UIntPtr.cs:229
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
static UIntPtr Subtract(UIntPtr pointer, int offset)
Subtracts an offset from the value of an unsigned pointer.
Definition: UIntPtr.cs:259
static unsafe bool operator==(UIntPtr value1, UIntPtr value2)
Determines whether two specified instances of T:System.UIntPtr are equal.
Definition: UIntPtr.cs:216
The exception that is thrown when one of the arguments provided to a method is not valid.
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
unsafe void * ToPointer()
Converts the value of this instance to a pointer to an unspecified type.
Definition: UIntPtr.cs:279
static UIntPtr operator -(UIntPtr pointer, int offset)
Subtracts an offset from the value of an unsigned pointer.
Definition: UIntPtr.cs:269
Specifies that the class can be serialized.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
static readonly UIntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Definition: UIntPtr.cs:20
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
unsafe ulong ToUInt64()
Converts the value of this instance to a 64-bit unsigned integer.
Definition: UIntPtr.cs:132