ByReference.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Runtime.CompilerServices;
  5. using System.Runtime.Versioning;
  6. namespace System
  7. {
  8. // ByReference<T> is meant to be used to represent "ref T" fields. It is working
  9. // around lack of first class support for byref fields in C# and IL. The JIT and
  10. // type loader has special handling for it that turns it into a thin wrapper around ref T.
  11. [NonVersionable]
  12. internal
  13. #if !PROJECTN // readonly breaks codegen contract and asserts UTC
  14. readonly
  15. #endif
  16. ref struct ByReference<T>
  17. {
  18. // CS0169: The private field '{blah}' is never used
  19. #pragma warning disable 169
  20. private readonly IntPtr _value;
  21. #pragma warning restore
  22. [Intrinsic]
  23. public ByReference(ref T value)
  24. {
  25. // Implemented as a JIT intrinsic - This default implementation is for
  26. // completeness and to provide a concrete error if called via reflection
  27. // or if intrinsic is missed.
  28. throw new PlatformNotSupportedException();
  29. }
  30. public ref T Value
  31. {
  32. [Intrinsic]
  33. get
  34. {
  35. // Implemented as a JIT intrinsic - This default implementation is for
  36. // completeness and to provide a concrete error if called via reflection
  37. // or if the intrinsic is missed.
  38. throw new PlatformNotSupportedException();
  39. }
  40. }
  41. }
  42. }