Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Expose IsReferenceOrContainsReferences in System.Runtime contract (#1…
Browse files Browse the repository at this point in the history
…6414)

Fixes #14047
  • Loading branch information
jkotas authored Feb 23, 2017
1 parent ca5e2ec commit 1f30744
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>() { throw null; }
}
[System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false, AllowMultiple = false)]
public partial class StateMachineAttribute : System.Attribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,5 +68,28 @@ private class ObjectWithDefaultCtor
{
public int Value = 42;
}

[Fact]
public static void IsReferenceOrContainsReferences()
{
Assert.False(RuntimeHelpers.IsReferenceOrContainsReferences<int>());
Assert.True(RuntimeHelpers.IsReferenceOrContainsReferences<string>());
Assert.False(RuntimeHelpers.IsReferenceOrContainsReferences<Guid>());
Assert.False(RuntimeHelpers.IsReferenceOrContainsReferences<StructWithoutReferences>());
Assert.True(RuntimeHelpers.IsReferenceOrContainsReferences<StructWithReferences>());
}

[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;
}
}
}

0 comments on commit 1f30744

Please sign in to comment.