From 1f30744026da22ee55dc24055717fafc8c3632f0 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 23 Feb 2017 12:01:35 -0800 Subject: [PATCH] Expose IsReferenceOrContainsReferences in System.Runtime contract (#16414) Fixes #14047 --- src/System.Runtime/ref/System.Runtime.cs | 3 ++- .../RuntimeHelpersTests.netcoreapp.cs | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index 8e4f5bb64e03..b604de48530a 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -6400,7 +6400,8 @@ public static void PrepareMethod(System.RuntimeMethodHandle method, System.Runti public static void ProbeForSufficientStack() { } public static bool TryEnsureSufficientExecutionStack() { throw null; } public static object GetUninitializedObject(Type type) { throw null; } - } + public static bool IsReferenceOrContainsReferences() { throw null; } + } [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false, AllowMultiple = false)] public partial class StateMachineAttribute : System.Attribute { diff --git a/src/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs b/src/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs index 160973fbe435..202428c135bb 100644 --- a/src/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs +++ b/src/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs @@ -2,6 +2,8 @@ // 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.InteropServices; + using Xunit; namespace System.Runtime.CompilerServices.Tests @@ -66,5 +68,28 @@ private class ObjectWithDefaultCtor { public int Value = 42; } + + [Fact] + public static void IsReferenceOrContainsReferences() + { + Assert.False(RuntimeHelpers.IsReferenceOrContainsReferences()); + Assert.True(RuntimeHelpers.IsReferenceOrContainsReferences()); + Assert.False(RuntimeHelpers.IsReferenceOrContainsReferences()); + Assert.False(RuntimeHelpers.IsReferenceOrContainsReferences()); + Assert.True(RuntimeHelpers.IsReferenceOrContainsReferences()); + } + + [StructLayoutAttribute(LayoutKind.Sequential)] + private struct StructWithoutReferences + { + public int a, b, c; + } + + [StructLayoutAttribute(LayoutKind.Sequential)] + private struct StructWithReferences + { + public int a, b, c; + public object d; + } } }