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;
27 assembly: System.CLSCompliant(true)
37 public unsafe struct IntPtr : ISerializable {
41 public static readonly IntPtr Zero;
45 Zero.value = (void *) 0;
48 public IntPtr (int i32)
53 public IntPtr (long i64)
61 unsafe public IntPtr (void *ptr)
66 public static int Size {
68 return sizeof (void *);
72 public void GetObjectData (SerializationInfo si, StreamingContext sc)
75 throw new ArgumentNullException( "si" );
77 si.AddValue("value", (long) value);
80 public override bool Equals (object o)
82 if (!(o is System.IntPtr))
85 return ((IntPtr) o).value == value;
88 public override int GetHashCode ()
98 public long ToInt64 ()
106 unsafe public void *ToPointer ()
111 override public string ToString ()
114 return ((int) value).ToString ();
116 return ((long) value).ToString ();
119 public static bool operator == (IntPtr a, IntPtr b)
121 return (a.value == b.value);
124 public static bool operator != (IntPtr a, IntPtr b)
126 return (a.value != b.value);
129 public static explicit operator IntPtr (int value)
131 return new IntPtr (value);
134 public static explicit operator IntPtr (long value)
136 return new IntPtr (value);
142 unsafe public static explicit operator IntPtr (void *value)
144 return new IntPtr (value);
147 public static explicit operator int (IntPtr value)
149 return (int) value.value;
152 public static explicit operator long (IntPtr value)
154 return (long) value.value;
160 unsafe public static explicit operator void * (IntPtr value)