Skip to content

Commit

Permalink
Moves ByReference to shared CoreLib (dotnet/coreclr#21633)
Browse files Browse the repository at this point in the history
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
marek-safar authored and dotnet-bot committed Dec 22, 2018
1 parent 1bbb577 commit f8bc3ff
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.TimeSpan.LittleG.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Text\Utf8Parser\Utf8Parser.TimeSpanSplitter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Byte.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ByReference.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Char.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\CharEnumerator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\CLSCompliantAttribute.cs" />
Expand Down
42 changes: 42 additions & 0 deletions netcore/System.Private.CoreLib/shared/System/ByReference.cs
Original file line number Diff line number Diff line change
@@ -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<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 has special handling for it that turns it into a thin wrapper around ref T.
[NonVersionable]
internal readonly ref struct ByReference<T>
{
// 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();
}
}
}
}

0 comments on commit f8bc3ff

Please sign in to comment.