From f8bc3ffc22ab91366426a2545898cbc42d4c70bb Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 21 Dec 2018 20:15:08 +0100 Subject: [PATCH] Moves ByReference to shared CoreLib (dotnet/coreclr#21633) Signed-off-by: dotnet-bot --- .../System.Private.CoreLib.Shared.projitems | 1 + .../shared/System/ByReference.cs | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 netcore/System.Private.CoreLib/shared/System/ByReference.cs diff --git a/netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index 0c40e26e9c66..27d43b76f8d2 100644 --- a/netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/netcore/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -111,6 +111,7 @@ + diff --git a/netcore/System.Private.CoreLib/shared/System/ByReference.cs b/netcore/System.Private.CoreLib/shared/System/ByReference.cs new file mode 100644 index 000000000000..492979a2d75b --- /dev/null +++ b/netcore/System.Private.CoreLib/shared/System/ByReference.cs @@ -0,0 +1,42 @@ +// 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; +using System.Runtime.Versioning; + +namespace System +{ + // ByReference 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 has special handling for it that turns it into a thin wrapper around ref T. + [NonVersionable] + internal readonly ref struct ByReference + { + // CS0169: The private field '{blah}' is never used +#pragma warning disable 169 + private readonly 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 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 PlatformNotSupportedException(); + } + } + } +}