mscorlib(4.0.0.0) API with additions
Pointer.cs
3 using System.Security;
4 
5 namespace System.Reflection
6 {
9  [CLSCompliant(false)]
10  [ComVisible(true)]
11  public sealed class Pointer : ISerializable
12  {
13  [SecurityCritical]
14  private unsafe void* _ptr;
15 
16  private RuntimeType _ptrType;
17 
18  private Pointer()
19  {
20  }
21 
22  [SecurityCritical]
23  private unsafe Pointer(SerializationInfo info, StreamingContext context)
24  {
25  _ptr = ((IntPtr)info.GetValue("_ptr", typeof(IntPtr))).ToPointer();
26  _ptrType = (RuntimeType)info.GetValue("_ptrType", typeof(RuntimeType));
27  }
28 
37  [SecurityCritical]
38  public unsafe static object Box(void* ptr, Type type)
39  {
40  if (type == null)
41  {
42  throw new ArgumentNullException("type");
43  }
44  if (!type.IsPointer)
45  {
46  throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), "ptr");
47  }
48  RuntimeType runtimeType = type as RuntimeType;
49  if (runtimeType == null)
50  {
51  throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), "ptr");
52  }
53  Pointer pointer = new Pointer();
54  pointer._ptr = ptr;
55  pointer._ptrType = runtimeType;
56  return pointer;
57  }
58 
64  [SecurityCritical]
65  public unsafe static void* Unbox(object ptr)
66  {
67  if (!(ptr is Pointer))
68  {
69  throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), "ptr");
70  }
71  return ((Pointer)ptr)._ptr;
72  }
73 
74  internal RuntimeType GetPointerType()
75  {
76  return _ptrType;
77  }
78 
79  [SecurityCritical]
80  internal unsafe object GetPointerValue()
81  {
82  return (IntPtr)_ptr;
83  }
84 
88  [SecurityCritical]
90  {
91  info.AddValue("_ptr", new IntPtr(_ptr));
92  info.AddValue("_ptrType", _ptrType);
93  }
94  }
95 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Definition: __Canon.cs:3
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
bool IsPointer
Gets a value indicating whether the T:System.Type is a pointer.
Definition: Type.cs:677
Provides a wrapper class for pointers.
Definition: Pointer.cs:11
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
The exception that is thrown when one of the arguments provided to a method is not valid.
static unsafe void * Unbox(object ptr)
Returns the stored pointer.
Definition: Pointer.cs:65
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
Specifies that the class can be serialized.
static unsafe object Box(void *ptr, Type type)
Boxes the supplied unmanaged memory pointer and the type associated with that pointer into a managed ...
Definition: Pointer.cs:38
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...