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)
36 public unsafe struct IntPtr : ISerializable {
40 public static IntPtr Zero;
44 Zero.value = (void *) 0;
47 public IntPtr (int i32)
52 public IntPtr (long i64)
60 unsafe public IntPtr (void *ptr)
65 public static int Size {
67 return sizeof (void *);
71 public void GetObjectData (SerializationInfo si, StreamingContext sc)
74 throw new ArgumentNullException( "si" );
76 si.AddValue("value", (long) value);
79 public override bool Equals (object o)
81 if (!(o is System.IntPtr))
84 return ((IntPtr) o).value == value;
87 public override int GetHashCode ()
97 public long ToInt64 ()
105 unsafe public void *ToPointer ()
110 override public string ToString ()
113 return ((int) value).ToString ();
115 return ((long) value).ToString ();
118 public static bool operator == (IntPtr a, IntPtr b)
120 return (a.value == b.value);
123 public static bool operator != (IntPtr a, IntPtr b)
125 return (a.value != b.value);
128 public static explicit operator IntPtr (int value)
130 return new IntPtr (value);
133 public static explicit operator IntPtr (long value)
135 return new IntPtr (value);
141 unsafe public static explicit operator IntPtr (void *value)
143 return new IntPtr (value);
146 public static explicit operator int (IntPtr value)
148 return (int) value.value;
151 public static explicit operator long (IntPtr value)
153 return (long) value.value;
159 unsafe public static explicit operator void * (IntPtr value)