diff options
3 files changed, 42 insertions, 17 deletions
diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj index 15ea8ef11..baf7c70b5 100644 --- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -222,6 +222,7 @@ <Compile Include="System\BadImageFormatException.cs" /> <Compile Include="System\Boolean.cs" /> <Compile Include="System\Buffer.cs" /> + <Compile Include="System\ByReference.cs" /> <Compile Include="System\Byte.cs" /> <Compile Include="System\Char.cs" /> <Compile Include="System\CharEnumerator.cs" /> diff --git a/src/System.Private.CoreLib/src/System/ByReference.cs b/src/System.Private.CoreLib/src/System/ByReference.cs new file mode 100644 index 000000000..d0129c2ee --- /dev/null +++ b/src/System.Private.CoreLib/src/System/ByReference.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.CompilerServices; + +namespace System +{ + // ByReference<T> is meant to be used to represent "ref T" fields. It is working + // around lack of first class support for byref fields in C# and IL. The JIT and + // type loader have special handling for it that turns it into a thin wrapper around ref T. + [StackOnly] + internal struct ByReference<T> + { + // CS0169: The private field '{blah}' is never used +#pragma warning disable 169 + private IntPtr _value; +#pragma warning restore + + [Intrinsic] + public ByReference(ref T value) + { + // Implemented as a JIT intrinsic - This default implementation is for + // completeness and to provide a concrete error if called via reflection + // or if intrinsic is missed. + throw new System.PlatformNotSupportedException(); + } + + public ref T Value + { + [Intrinsic] + get + { + // Implemented as a JIT intrinsic - This default implementation is for + // completeness and to provide a concrete error if called via reflection + // or if the intrinsic is missed. + throw new System.PlatformNotSupportedException(); + } + } + } +} diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs index 298b4e466..3ad095e91 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs @@ -21,21 +21,4 @@ namespace System.Runtime.CompilerServices [AttributeUsage(AttributeTargets.Struct)] public sealed class StackOnlyAttribute : Attribute { } - -#if false // Unused right now. It is likely going to be useful for Span<T> implementation. - // This is a dummy class to be replaced by the compiler with a ref T - // It has to be a dummy class to avoid complicated type substitution - // and other complications in the compiler. - public sealed class ByReference<T> - { - // - // Managed pointer creation - // - [Intrinsic] - public static extern ByReference<T> FromRef(ref T source); - - [Intrinsic] - public static extern ref T ToRef(ByReference<T> source); - } -#endif } |