Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Expose new .netcoreapp1.1 APIs in System.Runtime #12226

Merged
merged 5 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/System.Runtime/pkg/System.Runtime.pkgproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Runtime.csproj">
<ProjectReference Include="..\ref\System.Runtime.builds">
<SupportedFramework>net463;netcoreapp1.1;uap10.1;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Runtime.csproj">
Expand Down
11 changes: 11 additions & 0 deletions src/System.Runtime/ref/System.Runtime.builds
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.Runtime.csproj" />
<Project Include="System.Runtime.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
</Project>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>
30 changes: 30 additions & 0 deletions src/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ public void Initialize() { }
public static void Resize<T>(ref T[] array, int newSize) { }
public static void Reverse(System.Array array) { }
public static void Reverse(System.Array array, int index, int length) { }
#if netcoreapp11
public static void Reverse<T>(T[] array) { }
public static void Reverse<T>(T[] array, int index, int length) { }
#endif
public void SetValue(object value, int index) { }
public void SetValue(object value, int index1, int index2) { }
public void SetValue(object value, int index1, int index2, int index3) { }
Expand Down Expand Up @@ -983,6 +987,10 @@ protected Enum() { }
public static bool IsDefined(System.Type enumType, object value) { return default(bool); }
public static object Parse(System.Type enumType, string value) { return default(object); }
public static object Parse(System.Type enumType, string value, bool ignoreCase) { return default(object); }
#if netcoreapp11
public static TEnum Parse<TEnum>(String value) where TEnum : struct { return default(TEnum); }
public static TEnum Parse<TEnum>(String value, bool ignoreCase) where TEnum : struct { return default(TEnum); }
#endif
System.TypeCode System.IConvertible.GetTypeCode() { return default(System.TypeCode); }
bool System.IConvertible.ToBoolean(System.IFormatProvider provider) { return default(bool); }
byte System.IConvertible.ToByte(System.IFormatProvider provider) { return default(byte); }
Expand Down Expand Up @@ -1018,6 +1026,10 @@ protected Enum() { }
public string ToString(System.IFormatProvider provider) { return default(string); }
[System.ObsoleteAttribute("The provider argument is not used. Please use ToString(String).")]
public string ToString(string format, System.IFormatProvider provider) { return default(string); }
#if netcoreapp11
public static bool TryParse(System.Type enumType, string value, out object result) { result = default(object); return default(bool); }
public static bool TryParse(System.Type enumType, string value, bool ignoreCase, out object result) { result = default(object); return default(bool); }
#endif
public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct { result = default(TEnum); return default(bool); }
public static bool TryParse<TEnum>(string value, bool ignoreCase, out TEnum result) where TEnum : struct { result = default(TEnum); return default(bool); }
}
Expand Down Expand Up @@ -1332,6 +1344,9 @@ public partial struct Int64 : System.IComparable, System.IComparable<long>, Syst
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct IntPtr
#if netcoreapp11
: IEquatable<IntPtr>
#endif
{
public static readonly System.IntPtr Zero;
public IntPtr(int value) { throw new System.NotImplementedException(); }
Expand All @@ -1342,6 +1357,9 @@ public partial struct IntPtr
public static int Size { get { return default(int); } }
public static System.IntPtr Add(System.IntPtr pointer, int offset) { return default(System.IntPtr); }
public override bool Equals(object obj) { return default(bool); }
#if netcoreapp11
bool IEquatable<IntPtr>.Equals(IntPtr other) { return default(bool); }
#endif
public override int GetHashCode() { return default(int); }
public static System.IntPtr operator +(System.IntPtr pointer, int offset) { return default(System.IntPtr); }
public static bool operator ==(System.IntPtr value1, System.IntPtr value2) { return default(bool); }
Expand Down Expand Up @@ -1409,6 +1427,9 @@ public partial interface IProgress<in T>
public partial class Lazy<T>
{
public Lazy() { }
#if netcoreapp11
public Lazy(T value) { }
#endif
public Lazy(bool isThreadSafe) { }
public Lazy(System.Func<T> valueFactory) { }
public Lazy(System.Func<T> valueFactory, bool isThreadSafe) { }
Expand Down Expand Up @@ -2596,6 +2617,9 @@ public partial struct UInt64 : System.IComparable, System.IComparable<ulong>, Sy
[System.CLSCompliantAttribute(false)]
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct UIntPtr
#if netcoreapp11
: IEquatable<UIntPtr>
#endif
{
public static readonly System.UIntPtr Zero;
public UIntPtr(uint value) { throw new System.NotImplementedException(); }
Expand All @@ -2606,6 +2630,9 @@ public partial struct UIntPtr
public static int Size { get { return default(int); } }
public static System.UIntPtr Add(System.UIntPtr pointer, int offset) { return default(System.UIntPtr); }
public override bool Equals(object obj) { return default(bool); }
#if netcoreapp11
bool IEquatable<UIntPtr>.Equals(UIntPtr other) { return default(bool); }
#endif
public override int GetHashCode() { return default(int); }
public static System.UIntPtr operator +(System.UIntPtr pointer, int offset) { return default(System.UIntPtr); }
public static bool operator ==(System.UIntPtr value1, System.UIntPtr value2) { return default(bool); }
Expand Down Expand Up @@ -5593,6 +5620,9 @@ public static void PrepareMethod(System.RuntimeMethodHandle method) { }
public static void PrepareMethod(System.RuntimeMethodHandle method, System.RuntimeTypeHandle[] instantiation) { }
[System.Security.SecurityCriticalAttribute]
public static void ProbeForSufficientStack() { }
#if netcoreapp11
public static bool TryEnsureSufficientExecutionStack() { return default(bool); }
#endif
}
[System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false, AllowMultiple = false)]
public partial class StateMachineAttribute : System.Attribute
Expand Down
1 change: 1 addition & 0 deletions src/System.Runtime/ref/System.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<NuGetTargetMoniker>.NETStandard,Version=v1.7</NuGetTargetMoniker>
<PackageTargetFramework Condition="'$(TargetGroup)'==''">netstandard1.7;uap10.1</PackageTargetFramework>
<ProjectGuid>{ADBCF120-3454-4A3C-9D1D-AC4293E795D6}</ProjectGuid>
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp1.1'">$(DefineConstants);netcoreapp11</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Runtime.cs" />
Expand Down
7 changes: 2 additions & 5 deletions src/System.Runtime/ref/project.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"dependencies": {},
"frameworks": {
"netstandard1.7": {
"imports": [
"dotnet5.8"
]
}
"netstandard1.7": {},
"netcoreapp1.1": {},
}
}
4 changes: 4 additions & 0 deletions src/System.Runtime/tests/System.Runtime.Tests.builds
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<TestTFMs>netcoreapp1.0</TestTFMs>
</Project>
<Project Include="System.Runtime.Tests.csproj" />
<Project Include="System.Runtime.Tests.csproj">
<TargetGroup>netcoreapp1.1</TargetGroup>
<TestTFMs>netcoreapp1.1</TestTFMs>
</Project>
<Project Include="System.Runtime.Tests.csproj">
<TestTFMs>net462</TestTFMs>
<OSGroup>Windows_NT</OSGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/System.Runtime/tests/System.Runtime.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
<Link>Common\System\PlatformDetection.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp1.1'">
<Compile Include="System\ArrayTests.netcoreapp1.1.cs" />
<Compile Include="System\EnumTests.netcoreapp1.1.cs" />
<Compile Include="System\IntPtrTests.netcoreapp1.1.cs" />
<Compile Include="System\LazyTests.netcoreapp1.1.cs" />
<Compile Include="System\Runtime\CompilerServices\RuntimeHelpersTests.netcoreapp1.1.cs" />
<Compile Include="System\UIntPtrTests.netcoreapp1.1.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == ''">
<Compile Include="ArrayTests.netstandard1.7.cs" />
<Compile Include="CompareToTests.cs" />
Expand Down
16 changes: 8 additions & 8 deletions src/System.Runtime/tests/System/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace System.Tests
{
public static class ArrayTests
public static partial class ArrayTests
{
[Fact]
public static void IList_GetSetItem()
Expand Down Expand Up @@ -2665,8 +2665,8 @@ public static void Reverse_NullArray_ThrowsArgumentNullException()
[Fact]
public static void Reverse_MultidimensionalArray_ThrowsRankException()
{
Assert.Throws<RankException>(() => Array.Reverse(new int[10, 10]));
Assert.Throws<RankException>(() => Array.Reverse(new int[10, 10], 0, 0));
Assert.Throws<RankException>(() => Array.Reverse((Array)new int[10, 10]));
Assert.Throws<RankException>(() => Array.Reverse((Array)new int[10, 10], 0, 0));
}

[Theory]
Expand All @@ -2681,7 +2681,7 @@ public static void Reverse_IndexLessThanLowerBound_ThrowsArgumentOutOfRangeExcep
[Fact]
public static void Reverse_NegativeLength_ThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>("length", () => Array.Reverse(new int[10], 0, -1));
Assert.Throws<ArgumentOutOfRangeException>("length", () => Array.Reverse((Array)new int[10], 0, -1));
}

[Theory]
Expand All @@ -2691,15 +2691,15 @@ public static void Reverse_NegativeLength_ThrowsArgumentOutOfRangeException()
[InlineData(0, 11)]
public static void Reverse_InvalidIndexPlusLength_ThrowsArgumentException(int index, int length)
{
Assert.Throws<ArgumentException>(null, () => Array.Reverse(new int[10], index, length));
Assert.Throws<ArgumentException>(null, () => Array.Reverse((Array)new int[10], index, length));
}

[Fact]
public static unsafe void Reverse_ArrayOfPointers_ThrowsNotSupportedException()
{
Assert.Throws<NotSupportedException>(() => Array.Reverse(new int*[2]));
Array.Reverse(new int*[0]);
Array.Reverse(new int*[1]);
Assert.Throws<NotSupportedException>(() => Array.Reverse((Array)new int*[2]));
Array.Reverse((Array)new int*[0]);
Array.Reverse((Array)new int*[1]);
}

public static IEnumerable<object[]> Sort_Array_NonGeneric_TestData()
Expand Down
73 changes: 73 additions & 0 deletions src/System.Runtime/tests/System/ArrayTests.netcoreapp1.1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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.Collections.Generic;
using Xunit;

namespace System.Tests
{
public static partial class ArrayTests
{
public static IEnumerable<object[]> Reverse_Generic_Int_TestData()
{
// TODO: use (or merge this data into) Reverse_TestData if/when xunit/xunit#965 is merged
yield return new object[] { new int[] { 1, 2, 3 }, 0, 3, new int[] { 3, 2, 1 } };
yield return new object[] { new int[] { 1, 2, 3 }, 0, 2, new int[] { 2, 1, 3 } };
yield return new object[] { new int[] { 1, 2, 3 }, 1, 2, new int[] { 1, 3, 2 } };

// Nothing to reverse
yield return new object[] { new int[] { 1, 2, 3 }, 2, 1, new int[] { 1, 2, 3 } };
yield return new object[] { new int[] { 1, 2, 3 }, 0, 1, new int[] { 1, 2, 3 } };
yield return new object[] { new int[] { 1, 2, 3 }, 0, 0, new int[] { 1, 2, 3 } };
yield return new object[] { new int[] { 1, 2, 3 }, 3, 0, new int[] { 1, 2, 3 } };
yield return new object[] { new int[0], 0, 0, new int[0] };
}

[Theory]
[MemberData(nameof(Reverse_Generic_Int_TestData))]
public static void Reverse_Generic(int[] array, int index, int length, int[] expected)
{
if (index == 0 && length == array.Length)
{
int[] arrayClone1 = (int[])array.Clone();
Array.Reverse(arrayClone1);
Assert.Equal(expected, arrayClone1);
}
int[] arrayClone2 = (int[])array.Clone();
Array.Reverse(arrayClone2, index, length);
Assert.Equal(expected, arrayClone2);
}

[Fact]
public static void Reverse_Generic_NullArray_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>("array", () => Array.Reverse((string[])null));
Assert.Throws<ArgumentNullException>("array", () => Array.Reverse((string[])null, 0, 0));
}

[Fact]
public static void Reverse_Generic_NegativeIndex_ThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>("index", () => Array.Reverse(new string[0], -1, 0));
}

[Fact]
public static void Reverse_Generic_NegativeLength_ThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>("length", () => Array.Reverse(new string[0], 0, -1));
}

[Theory]
[InlineData(0, 0, 1)]
[InlineData(3, 4, 0)]
[InlineData(3, 3, 1)]
[InlineData(3, 2, 2)]
[InlineData(3, 1, 3)]
[InlineData(3, 0, 4)]
public static void Reverse_Generic_InvalidOffsetPlusLength_ThrowsArgumentException(int arrayLength, int index, int length)
{
Assert.Throws<ArgumentException>(null, () => Array.Reverse(new string[arrayLength], index, length));
}
}
}
75 changes: 75 additions & 0 deletions src/System.Runtime/tests/System/EnumTests.netcoreapp1.1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using Xunit;

namespace System.Tests
{
public static partial class EnumTests
{
[Theory]
[MemberData(nameof(Parse_TestData))]
public static void Parse_NetCoreApp11<T>(string value, bool ignoreCase, T expected) where T : struct
{
object result;
if (!ignoreCase)
{
Assert.True(Enum.TryParse(expected.GetType(), value, out result));
Assert.Equal(expected, result);

Assert.Equal(expected, Enum.Parse<T>(value));
}

Assert.True(Enum.TryParse(expected.GetType(), value, ignoreCase, out result));
Assert.Equal(expected, result);

Assert.Equal(expected, Enum.Parse<T>(value, ignoreCase));
}

[Theory]
[MemberData(nameof(Parse_Invalid_TestData))]
public static void Parse_Invalid_NetCoreApp11(Type enumType, string value, bool ignoreCase, Type exceptionType)
{
Type typeArgument = enumType == null || !enumType.GetTypeInfo().IsEnum ? typeof(SimpleEnum) : enumType;
MethodInfo parseMethod = typeof(EnumTests).GetTypeInfo().GetMethod(nameof(Parse_Generic_Invalid_NetCoreApp11)).MakeGenericMethod(typeArgument);
parseMethod.Invoke(null, new object[] { enumType, value, ignoreCase, exceptionType });
}

public static void Parse_Generic_Invalid_NetCoreApp11<T>(Type enumType, string value, bool ignoreCase, Type exceptionType) where T : struct
{
object result = null;
if (!ignoreCase)
{
if (enumType != null && enumType.IsEnum)
{
Assert.False(Enum.TryParse(enumType, value, out result));
Assert.Equal(default(object), result);

Assert.Throws(exceptionType, () => Enum.Parse<T>(value));
}
else
{
Assert.Throws(exceptionType, () => Enum.TryParse(enumType, value, out result));
Assert.Equal(default(object), result);
}
}

if (enumType != null && enumType.IsEnum)
{
Assert.False(Enum.TryParse(enumType, value, ignoreCase, out result));
Assert.Equal(default(object), result);

Assert.Throws(exceptionType, () => Enum.Parse<T>(value, ignoreCase));
}
else
{
Assert.Throws(exceptionType, () => Enum.TryParse(enumType, value, ignoreCase, out result));
Assert.Equal(default(object), result);
}
}
}
}
2 changes: 1 addition & 1 deletion src/System.Runtime/tests/System/IntPtrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace System.Tests
{
public static class IntPtrTests
public static partial class IntPtrTests
{
private static unsafe bool Is64Bit => sizeof(void*) == 8;

Expand Down
26 changes: 26 additions & 0 deletions src/System.Runtime/tests/System/IntPtrTests.netcoreapp1.1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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;
using System.Collections.Generic;
using Xunit;

namespace System.Tests
{
public static partial class IntPtrTests
{
[Theory]
[MemberData(nameof(Equals_TestData))]
public static void Equals_NetCoreApp11(IntPtr ptr, object obj, bool expected)
{
if (!(obj is IntPtr))
{
return;
}

IEquatable<IntPtr> iEquatable = ptr;
Assert.Equal(expected, iEquatable.Equals((IntPtr)obj));
}
}
}
Loading