2003-12-08 Patrik Torstensson <p@rxc.se>
[mono.git] / mcs / class / corlib / System.Reflection / Pointer.cs
1 //
2 // System.Reflection/Pointer.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc.  http://www.ximian.com
8 //
9 //
10
11 using System;
12 using System.Reflection;
13 using System.Globalization;
14 using System.Runtime.CompilerServices;
15 using System.Runtime.Serialization;
16
17 namespace System.Reflection {
18
19         [Serializable]
20         [CLSCompliant(false)]
21         public unsafe sealed class Pointer : ISerializable {
22
23                 void *data;
24                 Type type;
25
26                 private Pointer () {
27                 }
28                 
29                 public static Pointer Box (void *ptr, Type type) 
30                 {
31
32                         if (type == null)
33                                 throw new ArgumentNullException ("type");
34                         if (!type.IsPointer)
35                                 throw new ArgumentException ("type");
36                         Pointer res = new Pointer ();
37                         res.data = ptr;
38                         res.type = type;
39                         return res;
40                 }
41
42                 public static void* Unbox (object ptr)
43                 {
44                         Pointer p = ptr as Pointer;
45                         if (p == null)
46                                 throw new ArgumentException ("ptr");
47                         return p.data;
48                 }
49
50                 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
51                 {
52                         throw new NotSupportedException ("Pointer deserializatioon not supported.");
53                 }
54         }
55 }