ByReference.cs 1.5 KB

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