Pointer.cs 1.1 KB

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