5 // Miguel de Icaza (miguel@ximian.com)
8 // Michael Lambert, michaellambert@email.com
10 // (C) Ximian, Inc. http://www.ximian.com
12 // Remarks: Requires '/unsafe' compiler option. This class uses void*,
13 // in overloaded constructors, conversion, and cast members in
14 // the public interface. Using pointers is not valid CLS and
15 // the methods in question have been marked with the
16 // CLSCompliant attribute that avoid compiler warnings.
18 // FIXME: How do you specify a native int in C#? I am going to have to do some figuring out
22 using System.Runtime.Serialization;
25 assembly: System.CLSCompliant(true)
33 public unsafe struct IntPtr : ISerializable {
37 public static IntPtr Zero;
41 Zero.value = (void *) 0;
44 public IntPtr (int i32)
49 public IntPtr (long i64)
57 unsafe public IntPtr (void *ptr)
62 public static int Size {
64 return sizeof (void *);
68 public void GetObjectData (SerializationInfo si, StreamingContext sc)
71 throw new ArgumentNullException( "si" );
73 si.AddValue("value", (long) value);
76 public override bool Equals (object o)
78 if (!(o is System.IntPtr))
81 return ((IntPtr) o).value == value;
84 public override int GetHashCode ()
94 public long ToInt64 ()
102 unsafe public void *ToPointer ()
107 override public string ToString ()
110 return ((int) value).ToString ();
112 return ((long) value).ToString ();
115 public static bool operator == (IntPtr a, IntPtr b)
117 return (a.value == b.value);
120 public static bool operator != (IntPtr a, IntPtr b)
122 return (a.value != b.value);
125 public static explicit operator IntPtr (int value)
127 return new IntPtr (value);
130 public static explicit operator IntPtr (long value)
132 return new IntPtr (value);
138 unsafe public static explicit operator IntPtr (void *value)
140 return new IntPtr (value);
143 public static explicit operator int (IntPtr value)
145 return (int) value.value;
148 public static explicit operator long (IntPtr value)
150 return (long) value.value;
156 unsafe public static explicit operator void * (IntPtr value)