ByReference.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 readonly ref struct ByReference<T>
  13. {
  14. // CS0169: The private field '{blah}' is never used
  15. #pragma warning disable 169
  16. #pragma warning disable CA1823
  17. private readonly IntPtr _value;
  18. #pragma warning disable CA1823
  19. #pragma warning restore 169
  20. [Intrinsic]
  21. [MethodImpl(MethodImplOptions.InternalCall)]
  22. public ByReference(ref T value)
  23. {
  24. throw new PlatformNotSupportedException();
  25. }
  26. public ref T Value
  27. {
  28. [MethodImpl(MethodImplOptions.InternalCall)]
  29. get
  30. {
  31. // Implemented as a JIT intrinsic - This default implementation is for
  32. // completeness and to provide a concrete error if called via reflection
  33. // or if the intrinsic is missed.
  34. throw new PlatformNotSupportedException();
  35. }
  36. }
  37. }
  38. }