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; }
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; }
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; }
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; }
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; }
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; }
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; }
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
}
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; }
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; }
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; }
<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>
<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
<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
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference to the element at the specified index.
/// </summary>
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference to the element at the specified index in the read-only list.
/// </summary>
}
}
+#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>
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];
return false;
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
value = _additionalElements.ItemRef(index).Value;
#else
value = _additionalElements[index].Value;
return false;
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
actualKey = _additionalElements.ItemRef(index).Key;
#else
actualKey = _additionalElements[index].Key;
int index = _additionalElements.IndexOf(value, valueComparer);
if (index >= 0)
{
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
existingValue = _additionalElements.ItemRef(index);
#else
existingValue = _additionalElements[index];
{
get
{
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
return this.Root.ItemRef(index);
#else
return this.Root[index];
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference to the value for a given index into the list.
/// </summary>
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference to the element of the set at the given index.
/// </summary>
int end = index + count - 1;
while (start < end)
{
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
T a = result.ItemRef(start);
T b = result.ItemRef(end);
#else
/// <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>
return _forwards.Peek();
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference to the element at the front of the queue.
/// </summary>
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Returns a read-only reference to the value associated with the provided key.
/// </summary>
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>
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Returns a read-only reference to the value associated with the provided key.
/// </summary>
/// </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>
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference to the element of the set at the given index.
/// </summary>
{
get
{
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
return _root.ItemRef(index);
#else
return _root[index];
}
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference of the element of the set at the given index.
/// </summary>
return _head;
}
-#if FEATURE_ITEMREFAPI
+#if !NETSTANDARD10
/// <summary>
/// Gets a read-only reference to the element on the top of the stack.
/// </summary>
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)
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()
{
<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>