As Span and As Memory apis added for immutable arrays (dotnet/corefx#37757)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Tue, 21 May 2019 06:42:55 +0000 (23:42 -0700)
committerGitHub <noreply@github.com>
Tue, 21 May 2019 06:42:55 +0000 (23:42 -0700)
* As Span and As memory added for immutable arrays

* Fixing netstandard build

* using a more generic compile constant

* fixing build for netcoreapp

* building fix for netfx and netstandard

* fixing netstandard1.0, using generateRefereceASource to get ref file, tests for string and default immutable arrays

Commit migrated from https://github.com/dotnet/corefx/commit/51a1f16ee2aaded4ce1fca6847471b58f7ffa160

21 files changed:
src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs
src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.csproj
src/libraries/System.Collections.Immutable/src/System.Collections.Immutable.csproj
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Minimal.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableQueue_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.cs
src/libraries/System.Collections.Immutable/tests/ImmutableArrayTest.cs
src/libraries/mscorlib.WinRT-Facade/ref/mscorlib.WinRT-Facade.csproj

index 21f7830..870c4cc 100644 (file)
@@ -118,6 +118,10 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableArray<T> Add(T item) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> AddRange(System.Collections.Generic.IEnumerable<T> items) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> AddRange(System.Collections.Immutable.ImmutableArray<T> items) { throw null; }
+#if !NETSTANDARD10
+        public System.ReadOnlyMemory<T> AsMemory() { throw null; }
+        public System.ReadOnlySpan<T> AsSpan() { throw null; }
+#endif
         public System.Collections.Immutable.ImmutableArray<TOther> As<TOther>() where TOther : class { throw null; }
         public System.Collections.Immutable.ImmutableArray<TOther> CastArray<TOther>() where TOther : class { throw null; }
         public static System.Collections.Immutable.ImmutableArray<T> CastUp<TDerived>(System.Collections.Immutable.ImmutableArray<TDerived> items) where TDerived : class, T { throw null; }
@@ -138,7 +142,7 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableArray<T> Insert(int index, T item) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> InsertRange(int index, System.Collections.Immutable.ImmutableArray<T> items) { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         public ref readonly T ItemRef(int index) { throw null; }
 #endif
         public int LastIndexOf(T item) { throw null; }
@@ -223,7 +227,7 @@ namespace System.Collections.Immutable
             public int IndexOf(T item, int startIndex, int count) { throw null; }
             public int IndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
             public void Insert(int index, T item) { }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             public ref readonly T ItemRef(int index) { throw null; }
 #endif
             public int LastIndexOf(T item) { throw null; }
@@ -571,7 +575,7 @@ namespace System.Collections.Immutable
         public int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Insert(int index, T item) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         public ref readonly T ItemRef(int index) { throw null; }
 #endif
         public int LastIndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
@@ -661,7 +665,7 @@ namespace System.Collections.Immutable
             public int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
             public void Insert(int index, T item) { }
             public void InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             public ref readonly T ItemRef(int index) { throw null; }
 #endif
             public int LastIndexOf(T item) { throw null; }
@@ -719,7 +723,7 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableQueue<T> Enqueue(T value) { throw null; }
         public System.Collections.Immutable.ImmutableQueue<T>.Enumerator GetEnumerator() { throw null; }
         public T Peek() { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         public ref readonly T PeekRef() { throw null; }
 #endif
         System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator() { throw null; }
@@ -811,7 +815,7 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder ToBuilder() { throw null; }
         public bool TryGetKey(TKey equalKey, out TKey actualKey) { throw null; }
         public bool TryGetValue(TKey key, out TValue value) { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         public ref readonly TValue ValueRef(TKey key) { throw null; }
 #endif
         public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IComparer<TKey> keyComparer) { throw null; }
@@ -859,7 +863,7 @@ namespace System.Collections.Immutable
             public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutable() { throw null; }
             public bool TryGetKey(TKey equalKey, out TKey actualKey) { throw null; }
             public bool TryGetValue(TKey key, out TValue value) { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             public ref readonly TValue ValueRef(TKey key) { throw null; }
 #endif
         }
@@ -918,7 +922,7 @@ namespace System.Collections.Immutable
         public bool IsProperSupersetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
         public bool IsSubsetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
         public bool IsSupersetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         public ref readonly T ItemRef(int index) { throw null; }
 #endif
         public bool Overlaps(System.Collections.Generic.IEnumerable<T> other) { throw null; }
@@ -979,7 +983,7 @@ namespace System.Collections.Immutable
             public bool IsProperSupersetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
             public bool IsSubsetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
             public bool IsSupersetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             public ref readonly T ItemRef(int index) { throw null; }
 #endif
             public bool Overlaps(System.Collections.Generic.IEnumerable<T> other) { throw null; }
@@ -1022,7 +1026,7 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableStack<T> Clear() { throw null; }
         public System.Collections.Immutable.ImmutableStack<T>.Enumerator GetEnumerator() { throw null; }
         public T Peek() { throw null; }
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         public ref readonly T PeekRef() { throw null; }
 #endif
         public System.Collections.Immutable.ImmutableStack<T> Pop() { throw null; }
index 02bf613..c491c34 100644 (file)
@@ -3,9 +3,6 @@
     <ProjectGuid>{C7EFF4EE-70DC-453B-B817-4AF67921AB03}</ProjectGuid>
     <Configurations>netcoreapp-Debug;netcoreapp-Release;netstandard-Debug;netstandard-Release;netstandard1.0-Debug;netstandard1.0-Release;netstandard1.3-Debug;netstandard1.3-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(TargetGroup)' != 'netstandard1.0'">
-    <DefineConstants>$(DefineConstants);FEATURE_ITEMREFAPI</DefineConstants>
-  </PropertyGroup>
   <ItemGroup>
     <Compile Include="System.Collections.Immutable.cs" />
   </ItemGroup>
@@ -23,4 +20,7 @@
     <Reference Include="System.Collections" />
     <Reference Include="System.Runtime.InteropServices" />
   </ItemGroup>
+  <ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.3' or '$(TargetGroup)' == 'netstandard'">
+    <Reference Include="System.Memory" />
+  </ItemGroup>
 </Project>
\ No newline at end of file
index ea01147..1649010 100644 (file)
@@ -8,9 +8,6 @@
     <PackageTargetFramework Condition="'$(TargetGroup)' == 'netstandard1.0'">netstandard1.0;portable-net45+win8+wp8+wpa81</PackageTargetFramework>
     <Configurations>netcoreapp-Debug;netcoreapp-Release;netstandard-Debug;netstandard-Release;netstandard1.0-Debug;netstandard1.0-Release;netstandard1.3-Debug;netstandard1.3-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations>
   </PropertyGroup>
-  <PropertyGroup Condition="'$(TargetGroup)' != 'netstandard1.0'">
-    <DefineConstants>$(DefineConstants);FEATURE_ITEMREFAPI</DefineConstants>
-  </PropertyGroup>
   <ItemGroup>
     <Compile Include="Properties\InternalsVisibleTo.cs" />
     <Compile Include="GlobalSuppressions.cs" />
   <ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.3' or '$(TargetGroup)' == 'netcoreapp' or '$(TargetGroup)' == 'uap'">
     <Reference Include="System.Runtime.InteropServices" />
   </ItemGroup>
+  <ItemGroup Condition="'$(TargetGroup)' == 'netstandard1.3' or '$(TargetGroup)' == 'netstandard'">
+    <Reference Include="System.Memory" />
+  </ItemGroup>
 </Project>
\ No newline at end of file
index 4822157..c2dbc68 100644 (file)
@@ -159,7 +159,7 @@ namespace System.Collections.Immutable
                 }
             }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             /// <summary>
             /// Gets a read-only reference to the element at the specified index.
             /// </summary>
index db759ca..f453f29 100644 (file)
@@ -129,7 +129,7 @@ namespace System.Collections.Immutable
             }
         }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         /// <summary>
         /// Gets a read-only reference to the element at the specified index in the read-only list.
         /// </summary>
index 48981cf..2e87332 100644 (file)
@@ -92,6 +92,11 @@ namespace System.Collections.Immutable
             }
         }
 
+#if !NETSTANDARD10
+        public ReadOnlySpan<T> AsSpan() => new ReadOnlySpan<T>(array);
+
+        public ReadOnlyMemory<T> AsMemory() => new ReadOnlyMemory<T>(array);
+#endif
         /// <summary>
         /// Searches the array for the specified item.
         /// </summary>
index d00db01..995e45c 100644 (file)
@@ -186,7 +186,7 @@ namespace System.Collections.Immutable
                             result = OperationResult.NoChangeRequired;
                             return this;
                         case KeyCollisionBehavior.ThrowIfValueDifferent:
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                             ref readonly var existingEntry = ref _additionalElements.ItemRef(keyCollisionIndex);
 #else
                             var existingEntry = _additionalElements[keyCollisionIndex];
@@ -281,7 +281,7 @@ namespace System.Collections.Immutable
                     return false;
                 }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                 value = _additionalElements.ItemRef(index).Value;
 #else
                 value = _additionalElements[index].Value;
@@ -324,7 +324,7 @@ namespace System.Collections.Immutable
                     return false;
                 }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                 actualKey = _additionalElements.ItemRef(index).Key;
 #else
                 actualKey = _additionalElements[index].Key;
index 8f33e61..c1c1b90 100644 (file)
@@ -182,7 +182,7 @@ namespace System.Collections.Immutable
                     int index = _additionalElements.IndexOf(value, valueComparer);
                     if (index >= 0)
                     {
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                         existingValue = _additionalElements.ItemRef(index);
 #else
                         existingValue = _additionalElements[index];
index b37cc33..edc4c6a 100644 (file)
@@ -135,7 +135,7 @@ namespace System.Collections.Immutable
             {
                 get
                 {
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                     return this.Root.ItemRef(index);
 #else
                     return this.Root[index];
@@ -159,7 +159,7 @@ namespace System.Collections.Immutable
                 }
             }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             /// <summary>
             /// Gets a read-only reference to the value for a given index into the list.
             /// </summary>
index bb716eb..b7d4078 100644 (file)
@@ -187,7 +187,7 @@ namespace System.Collections.Immutable
                 }
             }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             /// <summary>
             /// Gets a read-only reference to the element of the set at the given index.
             /// </summary>
@@ -524,7 +524,7 @@ namespace System.Collections.Immutable
                 int end = index + count - 1;
                 while (start < end)
                 {
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                     T a = result.ItemRef(start);
                     T b = result.ItemRef(end);
 #else
index 81bbdda..66a455f 100644 (file)
@@ -169,13 +169,13 @@ namespace System.Collections.Immutable
         /// <param name="index">The 0-based index of the element in the set to return.</param>
         /// <returns>The element at the given position.</returns>
         /// <exception cref="IndexOutOfRangeException">Thrown from getter when <paramref name="index"/> is negative or not less than <see cref="Count"/>.</exception>
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         public T this[int index] => _root.ItemRef(index);
 #else
         public T this[int index] => _root[index];
 #endif
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         /// <summary>
         /// Gets a read-only reference to the element of the set at the given index.
         /// </summary>
index 02c1479..1f3c906 100644 (file)
@@ -138,7 +138,7 @@ namespace System.Collections.Immutable
             return _forwards.Peek();
         }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         /// <summary>
         /// Gets a read-only reference to the element at the front of the queue.
         /// </summary>
index 1f1f279..e7e7f8c 100644 (file)
@@ -202,7 +202,7 @@ namespace System.Collections.Immutable
                 }
             }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             /// <summary>
             /// Returns a read-only reference to the value associated with the provided key.
             /// </summary>
index 7b5ecd0..42c9416 100644 (file)
@@ -329,7 +329,7 @@ namespace System.Collections.Immutable
                 return this.RemoveRecursive(key, keyComparer, out mutated);
             }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             /// <summary>
             /// Returns a read-only reference to the value associated with the provided key.
             /// </summary>
index 5f1a399..ce1f976 100644 (file)
@@ -209,7 +209,7 @@ namespace System.Collections.Immutable
             }
         }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         /// <summary>
         /// Returns a read-only reference to the value associated with the provided key.
         /// </summary>
index 232a46f..324a5cc 100644 (file)
@@ -105,14 +105,14 @@ namespace System.Collections.Immutable
             /// </remarks>
             public T this[int index]
             {
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                 get { return _root.ItemRef(index); }
 #else
                 get { return _root[index]; }
 #endif
             }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             /// <summary>
             /// Gets a read-only reference to the element of the set at the given index.
             /// </summary>
index 6cb0043..3f58ff2 100644 (file)
@@ -253,7 +253,7 @@ namespace System.Collections.Immutable
                 }
             }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
             /// <summary>
             /// Gets a read-only reference to the element of the set at the given index.
             /// </summary>
index a610ed0..939ed15 100644 (file)
@@ -148,7 +148,7 @@ namespace System.Collections.Immutable
         {
             get
             {
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
                 return _root.ItemRef(index);
 #else
                 return _root[index];
@@ -156,7 +156,7 @@ namespace System.Collections.Immutable
             }
         }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         /// <summary>
         /// Gets a read-only reference of the element of the set at the given index.
         /// </summary>
index 7310af4..5cf5a23 100644 (file)
@@ -117,7 +117,7 @@ namespace System.Collections.Immutable
             return _head;
         }
 
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
         /// <summary>
         /// Gets a read-only reference to the element on the top of the stack.
         /// </summary>
index 925de26..cece077 100644 (file)
@@ -39,6 +39,15 @@ namespace System.Collections.Immutable.Tests
             yield return new object[] { s_empty };
         }
 
+        public static IEnumerable<object[]> StringImmutableArrayData()
+        {
+            yield return new object[] { new string[0] };
+            yield return new object[] { new[] { "a" } };
+            yield return new object[] { new[] { "a", "b", "c" } };
+            yield return new object[] { new[] { string.Empty } };
+            yield return new object[] { new[] { (string)null } };
+        }
+
         [Theory]
         [MemberData(nameof(Int32EnumerableData))]
         public void Clear(IEnumerable<int> source)
@@ -46,6 +55,104 @@ namespace System.Collections.Immutable.Tests
             Assert.True(s_empty == source.ToImmutableArray().Clear());
         }
 
+        [Theory]
+        [MemberData(nameof(Int32EnumerableData))]
+        public void AsSpanRoundTripTests(IEnumerable<int> source)
+        {
+            ImmutableArray<int> immutableArray = source.ToImmutableArray();
+            ReadOnlySpan<int> span = immutableArray.AsSpan();
+            Assert.Equal(immutableArray, span.ToArray());
+            Assert.Equal(immutableArray.Length, span.Length);
+        }
+
+        [Fact]
+        public void AsSpanRoundTripEmptyArrayTests()
+        {
+            ImmutableArray<int> immutableArray = ImmutableArray.Create(Array.Empty<int>());
+            ReadOnlySpan<int> span = immutableArray.AsSpan();
+            Assert.Equal(immutableArray, span.ToArray());
+            Assert.Equal(immutableArray.Length, span.Length);
+        }
+
+        [Fact]
+        public void AsSpanRoundTripDefaultArrayTests()
+        {
+            ImmutableArray<int> immutableArray = new ImmutableArray<int>();
+            ReadOnlySpan<int> span = immutableArray.AsSpan();
+            Assert.True(immutableArray.IsDefault);
+            Assert.Equal(0, span.Length);
+            Assert.True(span.IsEmpty);
+        }
+
+        [Theory]
+        [MemberData(nameof(StringImmutableArrayData))]
+        public void AsSpanRoundTripStringTests(IEnumerable<string> source)
+        {
+            ImmutableArray<string> immutableArray = source.ToImmutableArray();
+            ReadOnlySpan<string> span = immutableArray.AsSpan();
+            Assert.Equal(immutableArray, span.ToArray());
+            Assert.Equal(immutableArray.Length, span.Length);
+        }
+
+        [Fact]
+        public void AsSpanRoundTripDefaultArrayStringTests()
+        {
+            ImmutableArray<string> immutableArray = new ImmutableArray<string>();
+            ReadOnlySpan<string> span = immutableArray.AsSpan();
+            Assert.True(immutableArray.IsDefault);
+            Assert.Equal(0, span.Length);
+            Assert.True(span.IsEmpty);
+        }
+
+        [Theory]
+        [MemberData(nameof(Int32EnumerableData))]
+        public void AsMemoryRoundTripTests(IEnumerable<int> source)
+        {
+            ImmutableArray<int> immutableArray = source.ToImmutableArray();
+            ReadOnlyMemory<int> memory = immutableArray.AsMemory();
+            Assert.Equal(immutableArray, memory.ToArray());
+            Assert.Equal(immutableArray.Length, memory.Length);
+        }
+
+        [Fact]
+        public void AsMemoryRoundTripEmptyArrayTests()
+        {
+            ImmutableArray<int> immutableArray = ImmutableArray.Create(Array.Empty<int>());
+            ReadOnlyMemory<int> memory = immutableArray.AsMemory();
+            Assert.Equal(immutableArray, memory.ToArray());
+            Assert.Equal(immutableArray.Length, memory.Length);
+        }
+
+        [Fact]
+        public void AsMemoryRoundTripDefaultArrayTests()
+        {
+            ImmutableArray<int> immutableArray = new ImmutableArray<int>();
+            ReadOnlyMemory<int> memory = immutableArray.AsMemory();
+            Assert.True(immutableArray.IsDefault);
+            Assert.Equal(0, memory.Length);
+            Assert.True(memory.IsEmpty);
+        }
+
+        [Theory]
+        [MemberData(nameof(StringImmutableArrayData))]
+        public void AsMemoryRoundTripStringTests(IEnumerable<string> source)
+        {
+            ImmutableArray<string> immutableArray = source.ToImmutableArray();
+            ReadOnlyMemory<string> memory = immutableArray.AsMemory();
+            Assert.Equal(immutableArray, memory.ToArray());
+            Assert.Equal(immutableArray.Length, memory.Length);
+        }
+
+        [Fact]
+        public void AsMemoryRoundTripDefaultArrayStringTests()
+        {
+            ImmutableArray<string> immutableArray = new ImmutableArray<string>();
+            ReadOnlyMemory<string> memory = immutableArray.AsMemory();
+            Assert.True(immutableArray.IsDefault);
+            Assert.Equal(0, memory.Length);
+            Assert.True(memory.IsEmpty);
+        }
+
         [Fact]
         public void CreateEnumerableElementType()
         {
index a720212..6b4cf40 100644 (file)
@@ -8,7 +8,6 @@
     <BinPlaceRef>false</BinPlaceRef>
     <ProjectGuid>{4773F3C0-646E-4542-9FD5-D07A7737403A}</ProjectGuid>
     <Configurations>netcoreapp-Debug;netcoreapp-Release;netstandard-Debug;netstandard-Release;netstandard1.0-Debug;netstandard1.0-Release;uap-Debug;uap-Release</Configurations>
-    <DefineConstants Condition="'$(TargetGroup)' == 'netstandard1.0'">$(DefineConstants);NETSTANDARD10</DefineConstants>
     <DefineConstants Condition="'$(TargetGroup)' == 'netstandard1.2'">$(DefineConstants);NETSTANDARD12</DefineConstants>
   </PropertyGroup>
   <ItemGroup>