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 
5 using System.Runtime.CompilerServices;
6 
7 namespace System
8 {
9     // ByReference<T> is meant to be used to represent "ref T" fields. It is working
10     // around lack of first class support for byref fields in C# and IL. The JIT and
11     // type loader have special handling for it that turns it into a thin wrapper around ref T.
12     [System.Runtime.CompilerServices.DependencyReductionRoot] // TODO: put this in System.Private.ILToolchain contract instead
13     internal ref struct ByReference<T>
14     {
15         // CS0169: The private field '{blah}' is never used
16 #pragma warning disable 169
17         private IntPtr _value;
18 #pragma warning restore
19 
20         [Intrinsic]
ByReferenceSystem.ByReference21         public ByReference(ref T value)
22         {
23             // Implemented as a JIT intrinsic - This default implementation is for
24             // completeness and to provide a concrete error if called via reflection
25             // or if intrinsic is missed.
26             throw new NotSupportedException();
27         }
28 
29         public ref T Value
30         {
31             [Intrinsic]
32             get
33             {
34                 // Implemented as a JIT intrinsic - This default implementation is for
35                 // completeness and to provide a concrete error if called via reflection
36                 // or if the intrinsic is missed.
37                 throw new NotSupportedException();
38             }
39         }
40     }
41 }
42