using System.Collections;
using System.Collections.Specialized;
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
namespace System.CodeDom
#else
namespace System.Runtime.Serialization
#endif
{
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
public class CodeObject
#else
internal class CodeObject
using System.Diagnostics;
using System.Globalization;
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
namespace System.CodeDom
#else
namespace System.Runtime.Serialization
#endif
{
[Flags]
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
public enum CodeTypeReferenceOptions
#else
internal enum CodeTypeReferenceOptions
GenericTypeParameter = 0x00000002
}
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
public class CodeTypeReference : CodeObject
#else
internal sealed class CodeTypeReference : CodeObject
}
}
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
public CodeTypeReference(CodeTypeParameter typeParameter) :
this(typeParameter?.Name)
{
using System.Collections;
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
namespace System.CodeDom
#else
namespace System.Runtime.Serialization
#endif
{
-#if !FEATURE_SERIALIZATION
+#if CODEDOM
public class CodeTypeReferenceCollection : CollectionBase
#else
internal sealed class CodeTypeReferenceCollection : CollectionBase
#endif
public static unsafe string ToString(ReadOnlySpan<byte> bytes, Casing casing = Casing.Upper)
{
-#if NETFRAMEWORK || NETSTANDARD1_0 || NETSTANDARD1_3 || NETSTANDARD2_0
+#if NETFRAMEWORK || NETSTANDARD2_0
Span<char> result = stackalloc char[0];
if (bytes.Length > 16)
{
{
internal static partial class SR
{
-#if (!NETSTANDARD1_0 && !NETSTANDARD1_1 && !NET45) // AppContext is not supported on < NetStandard1.3 or < .NET Framework 4.5
+#if !NET45 // AppContext is not supported on < .NET Framework 4.5
private static readonly bool s_usingResourceKeys = AppContext.TryGetSwitch("System.Resources.UseSystemResourceKeys", out bool usingResourceKeys) ? usingResourceKeys : false;
#endif
// Native code generators can replace the value this returns based on user input at the time of native code generation.
// The Linker is also capable of replacing the value of this method when the application is being trimmed.
private static bool UsingResourceKeys() =>
-#if (!NETSTANDARD1_0 && !NETSTANDARD1_1 && !NET45) // AppContext is not supported on < NetStandard1.3 or < .NET Framework 4.5
+#if !NET45 // AppContext is not supported on < .NET Framework 4.5
s_usingResourceKeys;
#else
false;
</ItemGroup>
</Target>
- <!-- Adds Nullable annotation attributes to netstandard <= 2.0 builds -->
- <Choose>
- <When Condition="'$(Nullable)' != '' and ($(TargetFramework.StartsWith('netstandard1')) or '$(TargetFramework)' == 'netstandard2.0' or $(TargetFramework.StartsWith('netcoreapp2')) or '$(TargetFrameworkIdentifier)' == '.NETFramework')">
- <ItemGroup>
- <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\NullableAttributes.cs" Link="System\Diagnostics\CodeAnalysis\NullableAttributes.cs" />
- </ItemGroup>
- </When>
- </Choose>
+ <!-- Adds Nullable annotation attributes to < .NET 5 builds. -->
+ <ItemGroup Condition="'$(Nullable)' != '' and !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))">
+ <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\NullableAttributes.cs" Link="System\Diagnostics\CodeAnalysis\NullableAttributes.cs" />
+ </ItemGroup>
<PropertyGroup>
<ExcludeFromPackage Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)')) and '$(ExcludeCurrentNetCoreAppFromPackage)' == 'true'">true</ExcludeFromPackage>
<Project Sdk="Microsoft.Build.NoTargets">
+ <!-- Even though this project doesn't compile, we keep the csproj extension so that the source
+ package infra globs for .cs files. -->
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- The project doesn't compile anything therefore create the package during build. -->
<GeneratePackageOnBuild Condition="'$(BuildingAnOfficialBuildLeg)' != 'true'">true</GeneratePackageOnBuild>
<IsShipping>false</IsShipping>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
+ <!-- This is a source package which includes all .cs files by default. -->
<IsSourcePackage>true</IsSourcePackage>
<!-- This is non-shipping package. -->
<EnablePackageBaselineValidation>false</EnablePackageBaselineValidation>
<PackageDescription>Internal package for sharing Microsoft.Extensions.Hosting.HostFactoryResolver type.</PackageDescription>
</PropertyGroup>
-
- <ItemGroup>
- <Content Include="*.cs" PackagePath="contentFiles/cs/netstandard1.0/%(FileName)%(Extension)" BuildAction="Compile" />
- </ItemGroup>
</Project>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
- <IsPartialFacadeAssembly Condition="$(TargetFramework.StartsWith('net4'))">true</IsPartialFacadeAssembly>
+ <IsPartialFacadeAssembly Condition="'$(TargetFramework)' == 'net461'">true</IsPartialFacadeAssembly>
</PropertyGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
+ <ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true'">
<Compile Include="Microsoft\CSharp\CSharpCodeGenerator.cs" />
<Compile Include="Microsoft\CSharp\CSharpCodeGenerator.PlatformNotSupported.cs" />
<Compile Include="Microsoft\CSharp\CSharpCodeProvider.cs" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
<ItemGroup>
<ProjectReference Include="..\src\System.Collections.Immutable.csproj">
- <SupportedFramework>net45;netcore45;netcoreapp1.0;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<!-- Since UAP and .NETCoreApp are package based we still want to enable
<ValidatePackageSuppression Include="TreatAsOutOfBox">
<Value>.NETCoreApp;UAP</Value>
</ValidatePackageSuppression>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore45;netcore451;netcore50;uap10.0;net45;net451;net46;wp8;wpa81" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
\ No newline at end of file
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 !NETSTANDARD1_0
public System.ReadOnlyMemory<T> AsMemory() { throw null; }
public System.ReadOnlySpan<T> AsSpan() { throw null; }
-#endif
public System.Collections.Immutable.ImmutableArray<
#nullable disable
TOther
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 !NETSTANDARD1_0
public ref readonly T ItemRef(int index) { throw null; }
-#endif
public int LastIndexOf(T item) { throw null; }
public int LastIndexOf(T item, int startIndex) { throw null; }
public int LastIndexOf(T item, int startIndex, int count) { 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 !NETSTANDARD1_0
public ref readonly T ItemRef(int index) { throw null; }
-#endif
public int LastIndexOf(T item) { throw null; }
public int LastIndexOf(T item, int startIndex) { throw null; }
public int LastIndexOf(T item, int startIndex, int count) { throw null; }
public static System.Collections.Immutable.ImmutableHashSet<TSource> ToImmutableHashSet<TSource>(this System.Collections.Immutable.ImmutableHashSet<TSource>.Builder builder) { throw null; }
}
- #if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !NETSTANDARD2_0 && !NETFRAMEWORK
+ #if !NETSTANDARD2_0 && !NETFRAMEWORK
public sealed partial class ImmutableHashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.Generic.IReadOnlySet<T>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.Immutable.IImmutableSet<T>
#else
public sealed partial class ImmutableHashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.Immutable.IImmutableSet<T>
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 !NETSTANDARD1_0
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 System.Collections.Immutable.ImmutableList<T> Remove(T value) { throw null; }
public System.Collections.Immutable.ImmutableList<T> Remove(T value, 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 !NETSTANDARD1_0
public ref readonly T ItemRef(int index) { throw null; }
-#endif
public int LastIndexOf(T item) { throw null; }
public int LastIndexOf(T item, int startIndex) { throw null; }
public int LastIndexOf(T item, int startIndex, int count) { 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 !NETSTANDARD1_0
public ref readonly T PeekRef() { throw null; }
-#endif
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator() { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
System.Collections.Immutable.IImmutableQueue<T> System.Collections.Immutable.IImmutableQueue<T>.Clear() { 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, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
-#if !NETSTANDARD1_0
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> WithComparers(System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) { throw null; }
public sealed partial class Builder : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable
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, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
-#if !NETSTANDARD1_0
public ref readonly TValue ValueRef(TKey key) { throw null; }
-#endif
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public partial struct Enumerator : System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.IEnumerator, System.IDisposable
public static System.Collections.Immutable.ImmutableSortedSet<TSource> ToImmutableSortedSet<TSource>(this System.Collections.Immutable.ImmutableSortedSet<TSource>.Builder builder) { throw null; }
}
- #if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !NETSTANDARD2_0 && !NETFRAMEWORK
+#if !NETSTANDARD2_0 && !NETFRAMEWORK
public sealed partial class ImmutableSortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.Generic.ISet<T>, System.Collections.Generic.IReadOnlySet<T>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList, System.Collections.Immutable.IImmutableSet<T>
- #else
+#else
public sealed partial class ImmutableSortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList, System.Collections.Immutable.IImmutableSet<T>
- #endif
+#endif
{
internal ImmutableSortedSet() { }
public static readonly System.Collections.Immutable.ImmutableSortedSet<T> Empty;
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 !NETSTANDARD1_0
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.ImmutableSortedSet<T> Remove(T value) { throw null; }
public System.Collections.Generic.IEnumerable<T> Reverse() { 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 !NETSTANDARD1_0
public ref readonly T ItemRef(int index) { throw null; }
-#endif
public bool Overlaps(System.Collections.Generic.IEnumerable<T> other) { throw null; }
public bool Remove(T item) { throw null; }
public System.Collections.Generic.IEnumerable<T> Reverse() { 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 !NETSTANDARD1_0
public ref readonly T PeekRef() { throw null; }
-#endif
public System.Collections.Immutable.ImmutableStack<T> Pop() { throw null; }
public System.Collections.Immutable.ImmutableStack<T> Pop(out T value) { throw null; }
public System.Collections.Immutable.ImmutableStack<T> Push(T value) { throw null; }
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>$(NetCoreAppCurrent);netstandard1.0;netstandard1.3;netstandard2.0;net461</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
<Compile Include="System.Collections.Immutable.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
- <ProjectReference Include="..\..\System.Collections\ref\System.Collections.csproj" />
- <ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
- <ProjectReference Include="..\..\System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj" />
+ <ProjectReference Include="$(LibrariesProjectRoot)System.Collections\ref\System.Collections.csproj" />
+ <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\ref\System.Runtime.csproj" />
+ <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\ref\System.Runtime.InteropServices.csproj" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3' or
- '$(TargetFramework)' == 'netstandard2.0' or
- $(TargetFramework.StartsWith('net4'))">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
</ItemGroup>
- <!-- Include these transitive dependencies to overrule NuGet's ProjectReference over PackageReferene behavior. -->
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
- <PackageReference Include="System.Runtime.InteropServices" Version="$(SystemRuntimeInteropServicesVersion)" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard1.0'">
- <PackageReference Include="System.Runtime" Version="$(SystemRuntimeVersion)" />
- <PackageReference Include="System.Collections" Version="$(SystemCollectionsVersion)" />
- </ItemGroup>
</Project>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>$(NetCoreAppCurrent);netstandard1.0;netstandard1.3;netstandard2.0;net461</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
- <!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
- <PropertyGroup>
- <PackageTargetFramework Condition="'$(TargetFramework)' == 'netstandard1.0'">netstandard1.0;portable-net45+win8+wp8+wpa81</PackageTargetFramework>
- </PropertyGroup>
<ItemGroup>
<Compile Include="Properties\InternalsVisibleTo.cs" />
<Compile Include="System\Collections\Generic\IHashKeyCollection.cs" />
Link="Common\System\Runtime\Versioning\NonVersionableAttribute.cs" />
<None Include="Interfaces.cd" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.0' or '$(TargetFramework)' == 'netstandard1.3'">
- <Compile Include="$(CommonPath)System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs"
- Link="System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs" />
- </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<Reference Include="System.Collections" />
<Reference Include="System.Diagnostics.Contracts" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
</ItemGroup>
- <ItemGroup>
- <PackageReference Include="System.Diagnostics.Contracts" Condition="$(TargetFramework.StartsWith('netstandard1.'))" Version="$(SystemDiagnosticsContractsVersion)" />
- <PackageReference Include="System.Runtime.InteropServices" Condition="'$(TargetFramework)' == 'netstandard1.3'" Version="$(SystemRuntimeInteropServicesVersion)" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3' or
- '$(TargetFramework)' == 'netstandard2.0' or
- $(TargetFramework.StartsWith('net4'))">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'">
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element at the specified index.
/// </summary>
return ref this._elements[index];
}
-#endif
/// <summary>
/// Gets a value indicating whether the <see cref="ICollection{T}"/> is read-only.
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element at the specified index in the read-only list.
/// </summary>
// of removing array bounds checking to work.
return ref this.array![index];
}
-#endif
/// <summary>
/// Gets a value indicating whether this collection is empty.
}
}
-#if !NETSTANDARD1_0
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 !NETSTANDARD1_0
ref readonly var existingEntry = ref _additionalElements.ItemRef(keyCollisionIndex);
-#else
- var existingEntry = _additionalElements[keyCollisionIndex];
-#endif
if (!valueComparer.Equals(existingEntry.Value, value))
{
throw new ArgumentException(SR.Format(SR.DuplicateKey, key));
return false;
}
-#if !NETSTANDARD1_0
value = _additionalElements.ItemRef(index).Value;
-#else
- value = _additionalElements[index].Value;
-#endif
return true;
}
return false;
}
-#if !NETSTANDARD1_0
actualKey = _additionalElements.ItemRef(index).Key;
-#else
- actualKey = _additionalElements[index].Key;
-#endif
return true;
}
int index = _additionalElements.IndexOf(value, valueComparer);
if (index >= 0)
{
-#if !NETSTANDARD1_0
existingValue = _additionalElements.ItemRef(index);
-#else
- existingValue = _additionalElements[index];
-#endif
return true;
}
}
/// <typeparam name="T">The type of elements in the set.</typeparam>
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(ImmutableEnumerableDebuggerProxy<>))]
- #if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !NETSTANDARD2_0 && !NETFRAMEWORK
+#if !NETSTANDARD2_0 && !NETFRAMEWORK
public sealed partial class ImmutableHashSet<T> : IImmutableSet<T>, IHashKeyCollection<T>, IReadOnlyCollection<T>, ICollection<T>, ISet<T>, IReadOnlySet<T>, ICollection, IStrongEnumerable<T, ImmutableHashSet<T>.Enumerator>
- #else
+#else
public sealed partial class ImmutableHashSet<T> : IImmutableSet<T>, IHashKeyCollection<T>, IReadOnlyCollection<T>, ICollection<T>, ISet<T>, ICollection, IStrongEnumerable<T, ImmutableHashSet<T>.Enumerator>
- #endif
+#endif
{
/// <summary>
/// An empty immutable hash set with the default comparer for <typeparamref name="T"/>.
{
get
{
-#if !NETSTANDARD1_0
return this.Root.ItemRef(index);
-#else
- return this.Root[index];
-#endif
}
-
set
{
this.Root = this.Root.ReplaceAt(index, value);
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the value for a given index into the list.
/// </summary>
{
return ref this.Root.ItemRef(index);
}
-#endif
#endregion
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element of the set at the given index.
/// </summary>
return ref _key;
}
-#endif
#region IEnumerable<T> Members
int end = index + count - 1;
while (start < end)
{
-#if !NETSTANDARD1_0
T a = result.ItemRef(start);
T b = result.ItemRef(end);
-#else
- T a = result[start];
- T b = result[end];
-#endif
result = result
.ReplaceAt(end, a)
.ReplaceAt(start, b);
/// <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 !NETSTANDARD1_0
public T this[int index] => _root.ItemRef(index);
-#else
- public T this[int index] => _root[index];
-#endif
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element of the set at the given index.
/// </summary>
/// <returns>A read-only reference to the element at the given position.</returns>
/// <exception cref="IndexOutOfRangeException">Thrown when <paramref name="index"/> is negative or not less than <see cref="Count"/>.</exception>
public ref readonly T ItemRef(int index) => ref _root.ItemRef(index);
-#endif
#endregion
return _forwards.Peek();
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element at the front of the queue.
/// </summary>
return ref _forwards.PeekRef();
}
-#endif
/// <summary>
/// Adds an element to the back of the queue.
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Returns a read-only reference to the value associated with the provided key.
/// </summary>
return ref _root.ValueRef(key, _keyComparer);
}
-#endif
#endregion
return this.RemoveRecursive(key, keyComparer, out mutated);
}
-#if !NETSTANDARD1_0
/// <summary>
/// Returns a read-only reference to the value associated with the provided key.
/// </summary>
return ref match._value;
}
-#endif
/// <summary>
/// Tries to get the value.
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Returns a read-only reference to the value associated with the provided key.
/// </summary>
return ref _root.ValueRef(key, _keyComparer);
}
-#endif
#endregion
/// </remarks>
public T this[int index]
{
-#if !NETSTANDARD1_0
get { return _root.ItemRef(index); }
-#else
- get { return _root[index]; }
-#endif
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element of the set at the given index.
/// </summary>
{
return ref _root.ItemRef(index);
}
-#endif
/// <summary>
/// Gets the maximum value in the collection, as defined by the comparer.
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element of the set at the given index.
/// </summary>
return ref _key;
}
-#endif
#region IEnumerable<T> Members
/// </devremarks>
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(ImmutableEnumerableDebuggerProxy<>))]
- #if !NETSTANDARD1_0 && !NETSTANDARD1_3 && !NETSTANDARD2_0 && !NETFRAMEWORK
+#if !NETSTANDARD2_0 && !NETFRAMEWORK
public sealed partial class ImmutableSortedSet<T> : IImmutableSet<T>, ISortKeyCollection<T>, IReadOnlySet<T>, IReadOnlyList<T>, IList<T>, ISet<T>, IList, IStrongEnumerable<T, ImmutableSortedSet<T>.Enumerator>
- #else
+#else
public sealed partial class ImmutableSortedSet<T> : IImmutableSet<T>, ISortKeyCollection<T>, IReadOnlyList<T>, IList<T>, ISet<T>, IList, IStrongEnumerable<T, ImmutableSortedSet<T>.Enumerator>
- #endif
+#endif
{
/// <summary>
/// This is the factor between the small collection's size and the large collection's size in a bulk operation,
{
get
{
-#if !NETSTANDARD1_0
return _root.ItemRef(index);
-#else
- return _root[index];
-#endif
}
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference of the element of the set at the given index.
/// </summary>
{
return ref _root.ItemRef(index);
}
-#endif
#endregion
return _head!;
}
-#if !NETSTANDARD1_0
/// <summary>
/// Gets a read-only reference to the element on the top of the stack.
/// </summary>
return ref _head!;
}
-#endif
/// <summary>
/// Pushes an element onto a stack and returns the new stack.
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
<ItemGroup>
<ProjectReference Include="..\src\System.Diagnostics.DiagnosticSource.csproj">
- <SupportedFramework>net46;net45;netcore45;netcoreapp1.0;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net45;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
- <!-- this package is part of the implementation closure of NETStandard.Library
- therefore it cannot reference NETStandard.Library -->
- <SuppressMetaPackage Include="NETStandard.Library" />
<!-- Since UAP and .NETCoreApp are package based we still want to enable
OOBing libraries that happen to overlap with their framework package.
<ValidatePackageSuppression Include="TreatAsOutOfBox">
<Value>.NETCoreApp;UAP</Value>
</ValidatePackageSuppression>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore45;netcore451;netcore50;uap10.0;wp8;wpa81" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>netstandard2.0;netstandard1.1;netstandard1.3;net45</TargetFrameworks>
+ <TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<CLSCompliant>false</CLSCompliant>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
- <ExcludeFromPackage Condition="'$(TargetFramework)' == 'netstandard2.0'">true</ExcludeFromPackage>
- <DefineConstants Condition="$(TargetFramework.StartsWith('net4'))">$(DefineConstants);ALLOW_PARTIALLY_TRUSTED_CALLERS</DefineConstants>
- <!-- Avoid referencing NETStandard.Library on netstandard1.x since this package is part of that closure -->
- <DisableImplicitFrameworkReferences Condition="'$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'netstandard1.3'">true</DisableImplicitFrameworkReferences>
+ <DefineConstants Condition="'$(TargetFramework)' == 'net45'">$(DefineConstants);ALLOW_PARTIALLY_TRUSTED_CALLERS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Diagnostics.DiagnosticSource.cs" />
+ <Compile Include="System.Diagnostics.DiagnosticSourceActivity.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != 'netstandard1.1'">
- <Compile Include="System.Diagnostics.DiagnosticSourceActivity.cs" />
+ <ItemGroup>
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System.Runtime" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'netstandard1.3'">
- <PackageReference Include="System.Runtime" Version="$(SystemRuntimeVersion)" />
- </ItemGroup>
</Project>
\ No newline at end of file
<CLSCompliant>false</CLSCompliant>
<NoWarn>$(NoWarn);SA1205</NoWarn>
<Nullable>enable</Nullable>
- <TargetFrameworks>$(NetCoreAppCurrent);net5.0;netstandard1.1;netstandard1.3;net45;net46;netstandard2.0</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);net5.0;netstandard2.0;net46;net45</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
- <!-- To allow this library to work on V4.5 runtimes and other old platforms
- we also have a separate complilation of this DLL that works for V4.5
- (which is netstandard1.1). Again we duplicate in a portable-* folder
- to work with older NuGet clients -->
- <PackageTargetFramework Condition="'$(TargetFramework)' == 'netstandard1.1'">netstandard1.1;portable-net45+win8+wpa81</PackageTargetFramework>
- <DefineConstants Condition="'$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'net45'">$(DefineConstants);NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT;NO_ARRAY_EMPTY_SUPPORT</DefineConstants>
- <DefineConstants Condition="'$(TargetFramework)' != 'netstandard1.1'">$(DefineConstants);EVENTSOURCE_ACTIVITY_SUPPORT</DefineConstants>
- <DefineConstants Condition="'$(TargetFramework)' != 'netstandard1.1' and '$(TargetFramework)' != 'netstandard1.3'">$(DefineConstants);EVENTSOURCE_ENUMERATE_SUPPORT</DefineConstants>
- <DefineConstants Condition="$(TargetFramework.StartsWith('net4'))">$(DefineConstants);ALLOW_PARTIALLY_TRUSTED_CALLERS;ENABLE_HTTP_HANDLER</DefineConstants>
- <ExcludeFromPackage Condition="'$(TargetFramework)' == 'netstandard2.0'">true</ExcludeFromPackage>
+ <DefineConstants Condition="'$(TargetFramework)' == 'net45'">$(DefineConstants);NO_EVENTSOURCE_COMPLEX_TYPE_SUPPORT;NO_ARRAY_EMPTY_SUPPORT</DefineConstants>
+ <DefineConstants Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">$(DefineConstants);ALLOW_PARTIALLY_TRUSTED_CALLERS;ENABLE_HTTP_HANDLER</DefineConstants>
<DefineConstants Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">$(DefineConstants);W3C_DEFAULT_ID_FORMAT</DefineConstants>
- <!-- Avoid referencing NETStandard.Library on netstandard1.x since this package is part of that closure -->
- <DisableImplicitFrameworkReferences Condition="'$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'netstandard1.3'">true</DisableImplicitFrameworkReferences>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Diagnostics\DiagnosticSource.cs" />
<Compile Include="System\Diagnostics\DiagnosticSourceEventSource.cs" />
<None Include="DiagnosticSourceUsersGuide.md" />
</ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) != '.NETCoreApp'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != 'netstandard1.1'">
+ <ItemGroup>
<Compile Include="$(CommonPath)System\HexConverter.cs" Link="Common\System\HexConverter.cs" />
<Compile Include="System\Diagnostics\Activity.cs" />
<Compile Include="System\Diagnostics\ActivityStatusCode.cs" />
<Compile Include="System\Diagnostics\Metrics\ObservableInstrument.cs" />
<None Include="ActivityUserGuide.md" />
</ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Compile Include="System\Diagnostics\LocalAppContextSwitches.cs" />
<Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs">
<Link>Common\System\LocalAppContextSwitches.Common.cs</Link>
</Compile>
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != 'net45' And '$(TargetFramework)' != 'netstandard1.1'">
+ <ItemGroup Condition="'$(TargetFramework)' != 'net45'">
<Compile Include="System\Diagnostics\Activity.Current.net46.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Compile Include="System\Diagnostics\Activity.Current.net45.cs" />
</ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp' or
- '$(TargetFramework)' == 'netstandard1.1' or
- '$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' or
+ '$(TargetFramework)' == 'netstandard2.0'">
<Compile Include="System\Diagnostics\Activity.DateTime.corefx.cs" />
</ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp' or
- '$(TargetFramework)' == 'netstandard2.1'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Compile Include="System\Diagnostics\Activity.GenerateRootId.netcoreapp.cs" />
<Compile Include="System\Diagnostics\ActivityContext.netcoreapp.cs" />
<Compile Include="System\Diagnostics\ActivityLink.netcoreapp.cs" />
</ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) != '.NETCoreApp' and
- '$(TargetFramework)' != 'netstandard2.1' and
- '$(TargetFramework)' != 'netstandard1.1'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="System\Diagnostics\Activity.GenerateRootId.netfx.cs" />
<Compile Include="System\Diagnostics\ActivityContext.netfx.cs" />
<Compile Include="System\Diagnostics\ActivityLink.netfx.cs" />
</ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Compile Include="System\Diagnostics\HttpHandlerDiagnosticListener.cs" />
<Compile Include="AssemblyInfo.netfx.cs" />
<Compile Include="System\Diagnostics\Activity.DateTime.netfx.cs" />
</ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">
+ <ItemGroup>
+ <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj" />
+ </ItemGroup>
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Memory" />
<Reference Include="System.Reflection" />
<Reference Include="System.Runtime" />
- <Reference Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'" Include="System.Runtime.CompilerServices.Unsafe" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
<Reference Include="System.Resources.ResourceManager" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'netstandard1.3'">
- <PackageReference Include="System.Collections" Version="$(SystemCollectionsVersion)" />
- <PackageReference Include="System.Collections.Concurrent" Version="$(SystemCollectionsConcurrentVersion)" />
- <PackageReference Include="System.Diagnostics.Debug" Version="$(SystemDiagnosticsDebugVersion)" />
- <PackageReference Include="System.Diagnostics.Tools" Version="$(SystemDiagnosticsToolsVersion)" />
- <PackageReference Include="System.Diagnostics.Tracing" Version="$(SystemDiagnosticsTracingVersion)" />
- <PackageReference Include="System.Reflection" Version="$(SystemReflectionVersion)" />
- <PackageReference Include="System.Resources.ResourceManager" Version="$(SystemResourcesResourceManagerVersion)" />
- <PackageReference Include="System.Runtime" Version="$(SystemRuntimeVersion)" />
- <PackageReference Include="System.Runtime.InteropServices" Version="$(SystemRuntimeInteropServicesVersion)" />
- <PackageReference Include="System.Threading" Version="$(SystemThreadingVersion)" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
- <PackageReference Include="System.AppContext" Version="$(SystemAppContextVersion)" />
- <PackageReference Include="System.Runtime.Extensions" Version="$(SystemRuntimeExtensionsVersion)" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != 'netstandard1.1' and
- $([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) != '.NETCoreApp'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != 'netstandard1.1' and '$(TargetFramework)' != '$(NetCoreAppCurrent)'">
- <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj" />
- </ItemGroup>
</Project>
curSubscription.Observer.OnNext(new KeyValuePair<string, object?>(name, value));
}
- /// <summary>
- /// We don't have Activities in NetStandard1.1. but it is a pain to ifdef out all references to the Activity type
- /// in DiagnosticSubscription so we just define a private type for it here just so things compile.
- /// </summary>
-#if NETSTANDARD1_1
- private sealed class Activity {}
-#endif
-
// Note that Subscriptions are READ ONLY. This means you never update any fields (even on removal!)
private sealed class DiagnosticSubscription : IDisposable
{
while (startIdx < endIdx && char.IsWhiteSpace(filterAndPayloadSpecs[startIdx]))
startIdx++;
-#if EVENTSOURCE_ACTIVITY_SUPPORT
if (IsActivitySourceEntry(filterAndPayloadSpecs, startIdx, endIdx))
{
AddNewActivitySourceTransform(filterAndPayloadSpecs, startIdx, endIdx, eventSource);
}
else
-#endif // EVENTSOURCE_ACTIVITY_SUPPORT
{
specList = new FilterAndTransform(filterAndPayloadSpecs, startIdx, endIdx, eventSource, specList);
}
if (endIdx < 0)
break;
}
-#if EVENTSOURCE_ACTIVITY_SUPPORT
+
if (eventSource._activitySourceSpecs != null)
{
NormalizeActivitySourceSpecsList(eventSource);
CreateActivityListener(eventSource);
}
-#endif // EVENTSOURCE_ACTIVITY_SUPPORT
}
/// <summary>
/// <param name="eventSource"></param>
public static void DestroyFilterAndTransformList(ref FilterAndTransform? specList, DiagnosticSourceEventSource eventSource)
{
-#if EVENTSOURCE_ACTIVITY_SUPPORT
eventSource._activityListener?.Dispose();
eventSource._activityListener = null;
eventSource._activitySourceSpecs = null; // nothing to dispose inside this list.
-#endif // EVENTSOURCE_ACTIVITY_SUPPORT
var curSpec = specList;
specList = null; // Null out the list
}));
}
-#if EVENTSOURCE_ACTIVITY_SUPPORT
internal FilterAndTransform(string filterAndPayloadSpec, int endIdx, int colonIdx, string activitySourceName, string? activityName, ActivityEvents events, ActivitySamplingResult samplingResult, DiagnosticSourceEventSource eventSource)
{
_eventSource = eventSource;
eventSource._activitySourceSpecs = firstSpecificList;
}
-#endif // EVENTSOURCE_ACTIVITY_SUPPORT
private void Dispose()
{
// Specific ActivitySource Transforms information
-#if EVENTSOURCE_ACTIVITY_SUPPORT
internal const string c_ActivitySourcePrefix = "[AS]";
internal string? SourceName { get; set; }
internal string? ActivityName { get; set; }
internal DiagnosticSourceEventSource.ActivityEvents Events { get; set; }
internal ActivitySamplingResult SamplingResult { get; set; }
-#endif // EVENTSOURCE_ACTIVITY_SUPPORT
#region private
return new PropertyFetch(type); // returns null on any fetch.
if (propertyName == CurrentActivityPropertyName)
{
-#if EVENTSOURCE_ACTIVITY_SUPPORT
return new CurrentActivityPropertyFetch();
-#else
- // In netstandard1.1 the Activity.Current API doesn't exist
- Logger.Message($"{CurrentActivityPropertyName} not supported for this TFM");
- return new PropertyFetch(type);
-#endif
}
Debug.Assert(type != null, "Type should only be null for the well-known static fetchers already checked");
TypeInfo typeInfo = type.GetTypeInfo();
if (propertyName == EnumeratePropertyName)
{
-#if !EVENTSOURCE_ENUMERATE_SUPPORT
- // In netstandard1.1 and 1.3 the reflection APIs needed to implement Enumerate support aren't
- // available
- Logger.Message($"{EnumeratePropertyName} not supported for this TFM");
- return new PropertyFetch(type);
-#else
// If there are multiple implementations of IEnumerable<T>, this arbitrarily uses the first one
foreach (Type iFaceType in typeInfo.GetInterfaces())
{
// no implementation of IEnumerable<T> found, return a null fetcher
Logger.Message($"*Enumerate applied to non-enumerable type {type}");
return new PropertyFetch(type);
-#endif
}
else
{
private readonly StructFunc<TStruct, TProperty> _propertyFetch;
}
-
-#if EVENTSOURCE_ACTIVITY_SUPPORT
/// <summary>
/// A fetcher that returns the result of Activity.Current
/// </summary>
return Activity.Current;
}
}
-#endif
/// <summary>
/// A fetcher that enumerates and formats an IEnumerable
#endregion
private FilterAndTransform? _specs; // Transformation specifications that indicate which sources/events are forwarded.
-#if EVENTSOURCE_ACTIVITY_SUPPORT
private FilterAndTransform? _activitySourceSpecs; // ActivitySource Transformation specifications that indicate which sources/events are forwarded.
private ActivityListener? _activityListener;
-#endif // EVENTSOURCE_ACTIVITY_SUPPORT
#endregion
}
}
private static Delegate? GetHwndDelegate()
{
-#if !NETSTANDARD1_6
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
if (string.Equals(asm.GetName().Name, "System.Windows.Forms"))
}
}
}
-#endif
+
return null;
}
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
<ItemGroup>
<ProjectReference Include="..\ref\System.IO.Packaging.csproj">
- <SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net46;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.IO.Packaging.csproj" />
- <!--
- Suppress NETStandard.Library collpasing as it add more dependencies then needed in some
- scenarios like .NET Framework which adds an unecessary amount of package dependencies to download
- -->
- <SuppressMetaPackage Include="NETStandard.Library" />
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore50;uap10.0" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>netstandard2.0;netstandard1.3;net46</TargetFrameworks>
+ <TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
- <ItemGroup Condition="'$(TargetFramework)' != 'net46'">
- <Compile Include="System.IO.Packaging.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'net46'">
- <Compile Include="System.IO.Packaging.net46.cs" />
- </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
+ <Compile Include="System.IO.Packaging.cs" />
<Compile Include="System.IO.Packaging.Serialization.cs" />
<Compile Include="System.IO.Packaging.PackUriScheme.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
+ <Compile Include="System.IO.Packaging.net46.cs" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <TargetFrameworks>netstandard2.0;net46;netstandard1.3</TargetFrameworks>
+ <TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
- <DefineConstants Condition="'$(TargetFramework)' != 'netstandard1.3'">$(DefineConstants);FEATURE_SERIALIZATION</DefineConstants>
- <IsPartialFacadeAssembly Condition="$(TargetFramework.StartsWith('net4'))">true</IsPartialFacadeAssembly>
+ <IsPartialFacadeAssembly Condition="'$(TargetFramework)' == 'net46'">true</IsPartialFacadeAssembly>
</PropertyGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true'">
<Compile Include="System\IO\Packaging\CompressionOption.cs" />
<Compile Include="System\IO\Packaging\ZipPackagePart.cs" />
<Compile Include="System\IO\Packaging\ZipStreamManager.cs" />
<Compile Include="System\IO\Packaging\ZipWrappingStream.cs" />
- <Compile Condition="'$(TargetFramework)' != 'netstandard1.3'" Include="System\IO\Packaging\PackUriHelper.PackUriScheme.cs" />
+ <Compile Include="System\IO\Packaging\PackUriHelper.PackUriScheme.cs" />
</ItemGroup>
- <ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
+ <ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
\ No newline at end of file
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-#if FEATURE_SERIALIZATION
using System.Runtime.Serialization;
-#endif
namespace System.IO
{
/// The FileFormatException class is thrown when an input file or a data stream that is supposed to conform
/// to a certain file format specification is malformed.
/// </summary>
-#if FEATURE_SERIALIZATION
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
-#endif
public class FileFormatException : FormatException
{
/// <summary>
_sourceUri = sourceUri;
}
-#if FEATURE_SERIALIZATION
protected FileFormatException(SerializationInfo info, StreamingContext context) : base(info, context)
{
string? sourceUriString = info.GetString("SourceUri");
base.GetObjectData(info, context);
info.AddValue("SourceUri", SourceUri?.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped), typeof(string));
}
-#endif
/// <summary>
/// Returns the name of a file that caused this exception. This property may be equal to an empty string
2. We don't currently have a good mechanism for telling nuget to include the xml doc from the
implementation project in the ref folder for the generated package -->
<ProjectReference Include="..\src\System.Numerics.Tensors.csproj">
- <SupportedFramework>net45;wpa81;win8;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore45;netcore451;netcore50;uap10.0;net45;net451;net46;wpa81" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>netstandard2.0;netstandard1.1;net461</TargetFrameworks>
+ <TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <TargetFrameworks>netstandard2.0;netstandard1.1;net461</TargetFrameworks>
+ <TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
- <!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
- <PropertyGroup>
- <ExcludeFromPackage Condition="'$(TargetFramework)' == 'netstandard2.0'">true</ExcludeFromPackage>
- </PropertyGroup>
<ItemGroup>
<Compile Include="Properties\InternalsVisibleTo.cs" />
<Compile Include="System\Numerics\Tensors\ArrayTensorExtensions.cs" />
namespace System.Diagnostics.CodeAnalysis
{
+// These attributes already shipped with .NET Core 3.1 in System.Runtime
+#if !NETCOREAPP3_0 && !NETCOREAPP3_1 && !NETSTANDARD2_1
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
#if SYSTEM_PRIVATE_CORELIB
/// <summary>Gets the condition parameter value.</summary>
public bool ParameterValue { get; }
}
+#endif
/// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values.</summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
<PropertyGroup>
<NoWarn>$(NoWarn);1634;1691;649</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <DefineConstants>$(DefineConstants);FEATURE_SERIALIZATION</DefineConstants>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<!-- Too much private reflection. Do not bother with trimming -->
<ILLinkTrimAssembly>false</ILLinkTrimAssembly>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Reflection.Context.csproj">
- <SupportedFramework>uap10.0.16299;netcoreapp2.0;net45</SupportedFramework>
+ <SupportedFramework>uap10.0.16299;netcoreapp2.0;net45;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Reflection.Context.csproj" />
<InboxOnTargetFramework Include="net45">
<ValidatePackageSuppression Include="TreatAsOutOfBox">
<Value>UAP</Value>
</ValidatePackageSuppression>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore45;netcore451;netcore50;uap10.0;wpa81" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
plan on shipping a new desktop version out of band. Instead add API
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
- <TargetFrameworks>netstandard2.0;netstandard1.1</TargetFrameworks>
+ <TargetFrameworks>netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>netstandard2.1;netstandard2.0;netstandard1.1</TargetFrameworks>
+ <TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
else if (right == null)
return false;
- // This assembly should work in netstandard1.3,
- // so we cannot use MemberInfo.MetadataToken here.
- // Therefore, it compares honestly referring ECMA-335 I.8.6.1.6 Signature Matching.
+ // TODO: switch to use MemberInfo.MetadataToken here.
+ // It compares honestly referring ECMA-335 I.8.6.1.6 Signature Matching.
if (!Equals(left.DeclaringType, right.DeclaringType))
return false;
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
<ItemGroup>
<ProjectReference Include="..\src\System.Reflection.Metadata.csproj">
- <SupportedFramework>net45;netcore45;netcoreapp1.0;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<!-- Since UAP and .NETCoreApp are package based we still want to enable
<ValidatePackageSuppression Include="TreatAsOutOfBox">
<Value>.NETCoreApp;UAP</Value>
</ValidatePackageSuppression>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore45;netcore451;netcore50;uap10.0;net45;net451;net46;wpa81" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
\ No newline at end of file
+++ /dev/null
-// exclusions to work around netstandard1.1 builds, c.f. System.Reflection.Metadata.Manual.cs
-
-M:System.Reflection.Metadata.AssemblyDefinition.GetAssemblyName
-M:System.Reflection.Metadata.AssemblyReference.GetAssemblyName
-M:System.Reflection.Metadata.ImageFormatLimitationException.#ctor(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext)
namespace System.Reflection.Metadata
{
-#if !NETSTANDARD1_1
public readonly partial struct AssemblyDefinition
{
public System.Reflection.AssemblyName GetAssemblyName() { throw null; }
{
protected ImageFormatLimitationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
}
-#endif
}
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLSCompliant>false</CLSCompliant>
- <TargetFrameworks>$(NetCoreAppCurrent);netstandard1.1;netstandard2.0;net461</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Reflection.Metadata.cs" />
<Compile Include="System.Reflection.Metadata.Manual.cs" />
- <None Include="ReferenceSourceExcludeApi.txt" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
- <ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
- </ItemGroup>
- <!-- Include these transitive dependencies to overrule NuGet's ProjectReference over PackageReferene behavior. -->
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.1'">
- <PackageReference Include="System.Runtime" Version="$(SystemRuntimeVersion)" />
- <PackageReference Include="System.Collections" Version="$(SystemCollectionsVersion)" />
- <PackageReference Include="System.Runtime.InteropServices" Version="$(SystemRuntimeInteropServicesVersion)" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\..\System.Collections.Immutable\ref\System.Collections.Immutable.csproj" />
+ <ProjectReference Include="$(LibrariesProjectRoot)System.Collections.Immutable\ref\System.Collections.Immutable.csproj" />
+ </ItemGroup>
+ <ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
+ <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\ref\System.Runtime.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefaultLanguage>en-US</DefaultLanguage>
<CLSCompliant>false</CLSCompliant>
- <TargetFrameworks>$(NetCoreAppCurrent);netstandard1.1;netstandard2.0;net461</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<!-- Constrained Execution Regions only apply to netstandard2.0 and net4* -->
- <DefineConstants Condition="$(TargetFramework.StartsWith('netstandard2.0')) or $(TargetFramework.StartsWith('net4'))">$(DefineConstants);FEATURE_CER</DefineConstants>
- <PackageTargetFramework Condition="'$(TargetFramework)' == 'netstandard1.1'">netstandard1.1;portable-net45+win8</PackageTargetFramework>
+ <DefineConstants Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net461'">$(DefineConstants);FEATURE_CER</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs"
- Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)' "/>
+ Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' "/>
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs"
Link="Common\Interop\Windows\kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs"
- Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)' "/>
+ Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' "/>
<Compile Include="System\Reflection\Internal\Utilities\PinnedObject.cs" />
- <Compile Include="System\Reflection\Internal\Utilities\CriticalDisposableObject.cs" Condition="'$(TargetFramework)' != 'netstandard1.1'" />
- <Compile Include="System\Reflection\Internal\Utilities\CriticalDisposableObject.netstandard1.1.cs" Condition="'$(TargetFramework)' == 'netstandard1.1'" />
+ <Compile Include="System\Reflection\Internal\Utilities\CriticalDisposableObject.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ExceptionUtilities.cs" />
<Compile Include="System\Reflection\Internal\Utilities\PathUtilities.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\Encoding\FunctionPointerAttributes.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataBuilder.Heaps.cs" />
<Compile Include="System\Reflection\Metadata\IL\ILOpCodeExtensions.cs" />
<Compile Include="System\Reflection\Metadata\ImageFormatLimitationException.cs" />
- <Compile Include="System\Reflection\Metadata\ImageFormatLimitationException.Serialization.cs" Condition="'$(TargetFramework)' != 'netstandard1.1'" />
+ <Compile Include="System\Reflection\Metadata\ImageFormatLimitationException.Serialization.cs" />
<Compile Include="System\Reflection\Metadata\Internal\HeapSizeFlag.cs" />
<Compile Include="System\Reflection\Metadata\Internal\MetadataWriterUtilities.cs" />
<Compile Include="System\Reflection\Metadata\MetadataStreamOptions.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReaderProvider.cs" />
<Compile Include="System\Reflection\Metadata\BlobContentId.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\PrimitiveSerializationTypeCode.cs" />
- <Compile Include="System\Reflection\Metadata\TypeSystem\AssemblyDefinition.netstandard.cs" Condition="'$(TargetFramework)' != 'netstandard1.1'" />
- <Compile Include="System\Reflection\Metadata\TypeSystem\AssemblyReference.netstandard.cs" Condition="'$(TargetFramework)' != 'netstandard1.1'" />
+ <Compile Include="System\Reflection\Metadata\TypeSystem\AssemblyDefinition.netstandard.cs" />
+ <Compile Include="System\Reflection\Metadata\TypeSystem\AssemblyReference.netstandard.cs" />
<Compile Include="System\Reflection\Metadata\TypeSystem\Handles.TypeSystem.cs" />
<Compile Include="System\Reflection\PortableExecutable\ManagedPEBuilder.cs" />
<Compile Include="System\Reflection\PortableExecutable\ManagedTextSection.cs" />
<Compile Include="System\Reflection\Internal\Utilities\BitArithmetic.cs" />
<Compile Include="System\Reflection\Internal\Utilities\StringUtils.cs" />
<Compile Include="System\Reflection\Internal\Utilities\EmptyArray.cs" />
- <Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.cs" Condition="$(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('net4'))" />
- <Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.netcoreapp.cs" Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'" />
- <Compile Include="System\Reflection\Internal\Utilities\FileStreamReadLightUp.netcoreapp.cs" Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'" />
- <Compile Include="System\Reflection\Internal\Utilities\FileStreamReadLightUp.netstandard1.1.cs" Condition="'$(TargetFramework)' == 'netstandard1.1'" />
- <Compile Include="System\Reflection\Internal\Utilities\FileStreamReadLightUp.netstandard2.0.cs" Condition="'$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'net461'" />
+ <Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
+ <Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
+ <Compile Include="System\Reflection\Internal\Utilities\FileStreamReadLightUp.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
+ <Compile Include="System\Reflection\Internal\Utilities\FileStreamReadLightUp.netstandard2.0.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<Compile Include="System\Reflection\Internal\Utilities\Hash.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ImmutableByteArrayInterop.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ImmutableMemoryStream.cs" />
- <Compile Include="System\Reflection\Internal\Utilities\LightUpHelper.cs" Condition="$(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('net4'))" />
+ <Compile Include="System\Reflection\Internal\Utilities\LightUpHelper.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<Compile Include="System\Reflection\Internal\Utilities\MemoryBlock.cs" />
- <Compile Include="System\Reflection\Internal\Utilities\MemoryMapLightUp.cs" Condition="'$(TargetFramework)' != 'netstandard1.1'" />
- <Compile Include="System\Reflection\Internal\Utilities\MemoryMapLightUp.netstandard1.1.cs" Condition="'$(TargetFramework)' == 'netstandard1.1'" />
+ <Compile Include="System\Reflection\Internal\Utilities\MemoryMapLightUp.cs" />
<Compile Include="System\Reflection\Internal\Utilities\PooledStringBuilder.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ObjectPool`1.cs" />
<Compile Include="System\Reflection\Internal\Utilities\ReadOnlyUnmanagedMemoryStream.cs" />
<Compile Include="System\Reflection\Metadata\Signatures\MemberReferenceKind.cs" />
<Compile Include="System\Reflection\Metadata\Ecma335\MetadataAggregator.cs" />
<Compile Include="System\Reflection\Metadata\MetadataKind.cs" />
- <Compile Include="System\Reflection\Metadata\MetadataReader.netstandard.cs" Condition="'$(TargetFramework)' != 'netstandard1.1'" />
+ <Compile Include="System\Reflection\Metadata\MetadataReader.netstandard.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReader.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReader.WinMD.cs" />
<Compile Include="System\Reflection\Metadata\MetadataReaderOptions.cs" />
<Compile Include="System\Reflection\Throw.cs" />
<Compile Include="System\Reflection\System.Reflection.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Immutable" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.IO.MemoryMappedFiles" />
<Reference Include="System.Buffers" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.Immutable\src\System.Collections.Immutable.csproj" />
</ItemGroup>
</Project>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Internal
-{
- // HACK: CriticalFinalizerObject is not available in netstandard 1.x
- // Use CriticalHandle instead -- we don't actually use the handle,
- // just the fact that CriticalHandle derives from CriticalFinalizerObject to ensure critical finalizer.
- internal abstract class CriticalDisposableObject : CriticalHandle
- {
- public CriticalDisposableObject()
- : base(IntPtr.Zero)
- {
- }
-
- public sealed override bool IsInvalid => true;
-
- protected sealed override bool ReleaseHandle() =>
- throw ExceptionUtilities.Unreachable;
-
- protected new void SetHandle(IntPtr handle) =>
- throw ExceptionUtilities.Unreachable;
-
- protected sealed override void Dispose(bool disposing)
- {
- // do not call base dispose
- Release();
-
- if (disposing)
- {
- GC.SuppressFinalize(this);
- }
- }
-
- protected abstract void Release();
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics;
-using System.IO;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Internal
-{
- internal static class FileStreamReadLightUp
- {
- internal static Lazy<Type> FileStreamType = new Lazy<Type>(() =>
- {
- const string systemIOFileSystem = "System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken = b03f5f7f11d50a3a";
- const string mscorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
-
- return LightUpHelper.GetType("System.IO.FileStream", systemIOFileSystem, mscorlib);
- });
-
- internal static Lazy<PropertyInfo> SafeFileHandle = new Lazy<PropertyInfo>(() =>
- {
- return FileStreamType.Value.GetTypeInfo().GetDeclaredProperty("SafeFileHandle");
- });
-
- // internal for testing
- internal static bool readFileNotAvailable;
- internal static bool safeFileHandleNotAvailable;
-
- internal static bool IsFileStream(Stream stream)
- {
- if (FileStreamType.Value == null)
- {
- return false;
- }
-
- var type = stream.GetType();
- return type == FileStreamType.Value || type.GetTypeInfo().IsSubclassOf(FileStreamType.Value);
- }
-
- internal static SafeHandle GetSafeFileHandle(Stream stream)
- {
- Debug.Assert(FileStreamType.IsValueCreated && FileStreamType.Value != null && IsFileStream(stream));
-
- if (safeFileHandleNotAvailable)
- {
- return null;
- }
-
- PropertyInfo safeFileHandleProperty = SafeFileHandle.Value;
- if (safeFileHandleProperty == null)
- {
- safeFileHandleNotAvailable = true;
- return null;
- }
-
- SafeHandle handle;
- try
- {
- handle = (SafeHandle)safeFileHandleProperty.GetValue(stream);
- }
- catch (MemberAccessException)
- {
- safeFileHandleNotAvailable = true;
- return null;
- }
- catch (InvalidOperationException)
- {
- // thrown when accessing unapproved API in a Windows Store app
- safeFileHandleNotAvailable = true;
- return null;
- }
- catch (TargetInvocationException)
- {
- // Some FileStream implementations (e.g. IsolatedStorage) restrict access to the underlying handle by throwing
- // Tolerate it and fall back to slow path.
- return null;
- }
-
- if (handle != null && handle.IsInvalid)
- {
- // Also allow for FileStream implementations that do return a non-null, but invalid underlying OS handle.
- // This is how brokered files on WinRT will work. Fall back to slow path.
- return null;
- }
-
- return handle;
- }
-
- internal static unsafe int ReadFile(Stream stream, byte* buffer, int size)
- {
- if (readFileNotAvailable)
- {
- return 0;
- }
-
- SafeHandle handle = GetSafeFileHandle(stream);
- if (handle == null)
- {
- return 0;
- }
-
- try
- {
- int result = Interop.Kernel32.ReadFile(handle, buffer, size, out int bytesRead, IntPtr.Zero);
- return result == 0 ? 0 : bytesRead;
- }
- catch
- {
- readFileNotAvailable = true;
- return 0;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Diagnostics;
-using System.IO;
-using System.Runtime.ExceptionServices;
-using System.Runtime.InteropServices;
-
-namespace System.Reflection.Internal
-{
- internal static class MemoryMapLightUp
- {
- private static Type s_lazyMemoryMappedFileType;
- private static Type s_lazyMemoryMappedViewAccessorType;
- private static Type s_lazyMemoryMappedFileAccessType;
- private static Type s_lazyMemoryMappedFileSecurityType;
- private static Type s_lazyHandleInheritabilityType;
- private static MethodInfo s_lazyCreateFromFile;
- private static MethodInfo s_lazyCreateFromFileClassic;
- private static MethodInfo s_lazyCreateViewAccessor;
- private static PropertyInfo s_lazySafeMemoryMappedViewHandle;
- private static PropertyInfo s_lazyPointerOffset;
- private static FieldInfo s_lazyInternalViewField;
- private static PropertyInfo s_lazyInternalPointerOffset;
-
- private static readonly object s_MemoryMappedFileAccess_Read = 1;
- private static readonly object s_HandleInheritability_None = 0;
- private static readonly object s_LongZero = (long)0;
- private static readonly object s_True = true;
-
- private static bool? s_lazyIsAvailable;
-
- internal static bool IsAvailable
- {
- get
- {
- if (!s_lazyIsAvailable.HasValue)
- {
- s_lazyIsAvailable = TryLoadTypes();
- }
-
- return s_lazyIsAvailable.Value;
- }
- }
-
- private static bool TryLoadType(string typeName, string modernAssembly, string classicAssembly, out Type type)
- {
- type = LightUpHelper.GetType(typeName, modernAssembly, classicAssembly);
- return type != null;
- }
-
- private static bool TryLoadTypes()
- {
- const string systemIOMemoryMappedFiles = "System.IO.MemoryMappedFiles, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
- const string systemRuntimeHandles = "System.Runtime.Handles, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
- const string systemCore = "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
-
- TryLoadType("System.IO.MemoryMappedFiles.MemoryMappedFileSecurity", systemIOMemoryMappedFiles, systemCore, out s_lazyMemoryMappedFileSecurityType);
-
- return FileStreamReadLightUp.FileStreamType.Value != null
- && TryLoadType("System.IO.MemoryMappedFiles.MemoryMappedFile", systemIOMemoryMappedFiles, systemCore, out s_lazyMemoryMappedFileType)
- && TryLoadType("System.IO.MemoryMappedFiles.MemoryMappedViewAccessor", systemIOMemoryMappedFiles, systemCore, out s_lazyMemoryMappedViewAccessorType)
- && TryLoadType("System.IO.MemoryMappedFiles.MemoryMappedFileAccess", systemIOMemoryMappedFiles, systemCore, out s_lazyMemoryMappedFileAccessType)
- && TryLoadType("System.IO.HandleInheritability", systemRuntimeHandles, systemCore, out s_lazyHandleInheritabilityType)
- && TryLoadMembers();
- }
-
- private static bool TryLoadMembers()
- {
- // .NET Core, .NET 4.6+
- s_lazyCreateFromFile = LightUpHelper.GetMethod(
- s_lazyMemoryMappedFileType,
- "CreateFromFile",
- FileStreamReadLightUp.FileStreamType.Value,
- typeof(string),
- typeof(long),
- s_lazyMemoryMappedFileAccessType,
- s_lazyHandleInheritabilityType,
- typeof(bool)
- );
-
- // .NET < 4.6
- if (s_lazyCreateFromFile == null)
- {
- if (s_lazyMemoryMappedFileSecurityType != null)
- {
- s_lazyCreateFromFileClassic = LightUpHelper.GetMethod(
- s_lazyMemoryMappedFileType,
- "CreateFromFile",
- FileStreamReadLightUp.FileStreamType.Value,
- typeof(string),
- typeof(long),
- s_lazyMemoryMappedFileAccessType,
- s_lazyMemoryMappedFileSecurityType,
- s_lazyHandleInheritabilityType,
- typeof(bool));
- }
-
- if (s_lazyCreateFromFileClassic == null)
- {
- return false;
- }
- }
-
- s_lazyCreateViewAccessor = LightUpHelper.GetMethod(
- s_lazyMemoryMappedFileType,
- "CreateViewAccessor",
- typeof(long),
- typeof(long),
- s_lazyMemoryMappedFileAccessType);
-
- if (s_lazyCreateViewAccessor == null)
- {
- return false;
- }
-
- s_lazySafeMemoryMappedViewHandle = s_lazyMemoryMappedViewAccessorType.GetTypeInfo().GetDeclaredProperty("SafeMemoryMappedViewHandle");
- if (s_lazySafeMemoryMappedViewHandle == null)
- {
- return false;
- }
-
- // .NET Core, .NET 4.5.1+
- s_lazyPointerOffset = s_lazyMemoryMappedViewAccessorType.GetTypeInfo().GetDeclaredProperty("PointerOffset");
-
- // .NET < 4.5.1
- if (s_lazyPointerOffset == null)
- {
- s_lazyInternalViewField = s_lazyMemoryMappedViewAccessorType.GetTypeInfo().GetDeclaredField("m_view");
- if (s_lazyInternalViewField == null)
- {
- return false;
- }
-
- s_lazyInternalPointerOffset = s_lazyInternalViewField.FieldType.GetTypeInfo().GetDeclaredProperty("PointerOffset");
- if (s_lazyInternalPointerOffset == null)
- {
- return false;
- }
- }
-
- return true;
- }
-
- internal static IDisposable CreateMemoryMap(Stream stream)
- {
- Debug.Assert(s_lazyIsAvailable.GetValueOrDefault());
-
- try
- {
- if (s_lazyCreateFromFile != null)
- {
- return (IDisposable)s_lazyCreateFromFile.Invoke(null, new object[6]
- {
- stream, // fileStream
- null, // mapName
- s_LongZero, // capacity
- s_MemoryMappedFileAccess_Read, // access
- s_HandleInheritability_None, // inheritability
- s_True, // leaveOpen
- });
- }
- else
- {
- Debug.Assert(s_lazyCreateFromFileClassic != null);
- return (IDisposable)s_lazyCreateFromFileClassic.Invoke(null, new object[7]
- {
- stream, // fileStream
- null, // mapName
- s_LongZero, // capacity
- s_MemoryMappedFileAccess_Read, // access
- null, // memoryMappedFileSecurity
- s_HandleInheritability_None, // inheritability
- s_True, // leaveOpen
- });
- }
- }
- catch (MemberAccessException)
- {
- s_lazyIsAvailable = false;
- return null;
- }
- catch (InvalidOperationException)
- {
- // thrown when accessing unapproved API in a Windows Store app
- s_lazyIsAvailable = false;
- return null;
- }
- catch (TargetInvocationException ex)
- {
- ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
- throw;
- }
- }
-
- internal static IDisposable CreateViewAccessor(object memoryMap, long start, int size)
- {
- Debug.Assert(s_lazyIsAvailable.GetValueOrDefault());
- try
- {
- return (IDisposable)s_lazyCreateViewAccessor.Invoke(memoryMap, new object[3]
- {
- start, // start
- (long)size, // size
- s_MemoryMappedFileAccess_Read, // access
- });
- }
- catch (MemberAccessException)
- {
- s_lazyIsAvailable = false;
- return null;
- }
- catch (InvalidOperationException)
- {
- s_lazyIsAvailable = false;
- return null;
- }
- catch (TargetInvocationException ex) when (ex.InnerException is UnauthorizedAccessException)
- {
- throw new IOException(ex.InnerException.Message, ex.InnerException);
- }
- catch (TargetInvocationException ex)
- {
- ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
- throw;
- }
- }
-
- internal static bool TryGetSafeBufferAndPointerOffset(object accessor, out SafeBuffer safeBuffer, out long offset)
- {
- Debug.Assert(s_lazyIsAvailable.GetValueOrDefault());
-
- safeBuffer = (SafeBuffer)s_lazySafeMemoryMappedViewHandle.GetValue(accessor);
- offset = 0;
-
- try
- {
- if (s_lazyPointerOffset != null)
- {
- offset = (long)s_lazyPointerOffset.GetValue(accessor);
- }
- else
- {
- object internalView = s_lazyInternalViewField.GetValue(accessor);
- offset = (long)s_lazyInternalPointerOffset.GetValue(internalView);
- }
-
- return true;
- }
- catch (MemberAccessException)
- {
- s_lazyIsAvailable = false;
- return false;
- }
- catch (InvalidOperationException)
- {
- // thrown when accessing unapproved API in a Windows Store app
- s_lazyIsAvailable = false;
- return false;
- }
- catch (TargetInvocationException ex)
- {
- ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
- throw;
- }
- }
- }
-}
<ItemGroup>
<PackageIndex Include="$(PkgDir)baseline\packageBaseline.1.1.json" />
<ProjectReference Include="..\ref\System.Runtime.CompilerServices.Unsafe.csproj">
- <SupportedFramework>net45;netcoreapp1.0;netcore50;netcore45;wp8;wpa81;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net45;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Runtime.CompilerServices.Unsafe.ilproj" />
- <!-- this package is part of the implementation closure of NETStandard.Library
- therefore it cannot reference NETStandard.Library -->
- <SuppressMetaPackage Include="NETStandard.Library" />
-
<!-- Since UAP and .NETCoreApp are package based we still want to enable
OOBing libraries that happen to overlap with their framework package.
This avoids us having to lock the API in our NuGet packages just
<ValidatePackageSuppression Include="TreatAsOutOfBox">
<Value>.NETCoreApp;UAP</Value>
</ValidatePackageSuppression>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore45;netcore451;netcore50;uap10.0;wp8;wpa81" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
\ No newline at end of file
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CLSCompliant>false</CLSCompliant>
<Nullable>enable</Nullable>
- <TargetFrameworks>netstandard2.0;netstandard1.0;netstandard2.1;net45;net461</TargetFrameworks>
+ <TargetFrameworks>netstandard2.1;netstandard2.0;net461;net45</TargetFrameworks>
<ExcludeFromPackage Condition="'$(TargetFramework)' == 'net45'">true</ExcludeFromPackage>
</PropertyGroup>
<ItemGroup>
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
- <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;netcoreapp2.0;netstandard1.0;net45</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;netcoreapp2.0;net45</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<!-- Make sure that the DebuggableAttribute is set properly. -->
<DebugOptimization>IMPL</DebugOptimization>
<ExtraMacros Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)' or '$(TargetFramework)' == 'netcoreapp2.0'">#define netcoreapp</ExtraMacros>
<CoreAssembly>System.Runtime</CoreAssembly>
<CoreAssembly Condition="'$(TargetFramework)' == 'netstandard2.0'">netstandard</CoreAssembly>
- <DisableImplicitFrameworkReferences Condition="'$(TargetFramework)' == 'netstandard1.0'">true</DisableImplicitFrameworkReferences>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">
<CoreAssembly>mscorlib</CoreAssembly>
<!-- mscorlib is passed in as an explicit reference from C# targets but not via the IL SDK. -->
<Reference Include="$(CoreAssembly)"
Condition="!$(TargetFramework.StartsWith('netstandard'))" />
-
- <PackageReference Include="System.Runtime" Version="$(SystemRuntimeVersion)"
- Condition="'$(TargetFramework)' == 'netstandard1.0'" />
</ItemGroup>
<Target Name="GenerateVersionFile"
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
<ItemGroup>
<ProjectReference Include="..\src\System.Threading.Channels.csproj">
- <SupportedFramework>net46;netcore50;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
- </ItemGroup>
- <ItemGroup>
+
<!-- Allow the package to carry an OOB implementation for .NETCore. -->
<ValidatePackageSuppression Include="TreatAsOutOfBox">
<Value>.NETCoreApp</Value>
</ValidatePackageSuppression>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore50;uap10.0;net46" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard1.3;netstandard2.0;netstandard2.1;net461</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Threading.Channels.cs" />
+ <Compile Include="System.Threading.Channels.netstandard21.cs"
+ Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != 'netstandard1.3' and
- '$(TargetFramework)' != 'netstandard2.0' and
- '$(TargetFramework)' != 'net461'">
- <Compile Include="System.Threading.Channels.netstandard21.cs" />
+ <ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
+ <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime/ref/System.Runtime.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
<Reference Include="System.Runtime" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
- <ProjectReference Include="$(LibrariesProjectRoot)System.Runtime/ref/System.Runtime.csproj" />
- </ItemGroup>
- <ItemGroup Condition="$(TargetFramework.StartsWith('netstandard')) or
- '$(TargetFramework)' == 'net461'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<PackageReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" />
- <!-- Include these transitive dependencies to overrule NuGet's ProjectReference over PackageReferene behavior. -->
- <PackageReference Include="System.Runtime" Version="$(SystemRuntimeVersion)" Condition="'$(TargetFramework)' == 'netstandard1.3'" />
</ItemGroup>
</Project>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>$(NetCoreAppCurrent);netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.0;net461</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
<Compile Include="System\VoidResult.cs" />
<Compile Include="System\Collections\Generic\Deque.cs" />
<Compile Include="System\Threading\Channels\AsyncOperation.cs" />
- <Compile Include="System\Threading\Channels\AsyncOperation.netcoreapp.cs" Condition="!$(TargetFramework.StartsWith('netstandard')) AND !$(TargetFramework.StartsWith('net4'))" />
- <Compile Include="System\Threading\Channels\AsyncOperation.netstandard1.cs" Condition="$(TargetFramework.StartsWith('netstandard1.'))" />
- <Compile Include="System\Threading\Channels\AsyncOperation.netstandard2.cs" Condition="$(TargetFramework.StartsWith('netstandard2.')) OR $(TargetFramework.StartsWith('net4'))" />
+ <Compile Include="System\Threading\Channels\AsyncOperation.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
+ <Compile Include="System\Threading\Channels\AsyncOperation.netstandard2.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<Compile Include="System\Threading\Channels\BoundedChannel.cs" />
<Compile Include="System\Threading\Channels\BoundedChannelFullMode.cs" />
<Compile Include="System\Threading\Channels\Channel.cs" />
<Compile Include="System\Threading\Channels\ChannelClosedException.cs" />
- <Compile Include="System\Threading\Channels\ChannelClosedException.netstandard21.cs" Condition="'$(TargetFramework)' != 'netstandard1.3' AND '$(TargetFramework)' != 'netstandard2.0' AND !$(TargetFramework.StartsWith('net4'))" />
+ <Compile Include="System\Threading\Channels\ChannelClosedException.netstandard21.cs"
+ Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))" />
<Compile Include="System\Threading\Channels\ChannelOptions.cs" />
<Compile Include="System\Threading\Channels\ChannelReader.cs" />
- <Compile Include="System\Threading\Channels\ChannelReader.netstandard21.cs" Condition="'$(TargetFramework)' != 'netstandard1.3' AND '$(TargetFramework)' != 'netstandard2.0' AND !$(TargetFramework.StartsWith('net4'))" />
+ <Compile Include="System\Threading\Channels\ChannelReader.netstandard21.cs"
+ Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))" />
<Compile Include="System\Threading\Channels\ChannelUtilities.cs" />
<Compile Include="System\Threading\Channels\ChannelWriter.cs" />
<Compile Include="System\Threading\Channels\Channel_1.cs" />
<Compile Include="$(CommonPath)System\Collections\Concurrent\SingleProducerConsumerQueue.cs"
Link="Common\System\Collections\Concurrent\SingleProducerConsumerQueue.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)' or
- '$(TargetFramework)' == 'netcoreapp3.0'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Threading.Tasks" />
<Reference Include="System.Threading.Tasks.Extensions" />
</ItemGroup>
- <ItemGroup Condition="$(TargetFramework.StartsWith('netstandard')) or
- $(TargetFramework.StartsWith('net4'))">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<PackageReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj" />
</ItemGroup>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Threading.Tasks;
-
-namespace System.Threading.Channels
-{
- internal partial class AsyncOperation<TResult>
- {
- private void UnsafeQueueSetCompletionAndInvokeContinuation() =>
- Task.Factory.StartNew(s => ((AsyncOperation<TResult>)s).SetCompletionAndInvokeContinuation(), this,
- CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
-
- private void UnsafeQueueUserWorkItem(Action<object?> action, object? state) =>
- QueueUserWorkItem(action, state);
-
- private static void QueueUserWorkItem(Action<object?> action, object? state) =>
- Task.Factory.StartNew(action, state,
- CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
-
- private static CancellationTokenRegistration UnsafeRegister(CancellationToken cancellationToken, Action<object?> action, object? state) =>
- cancellationToken.Register(action, state);
- }
-}
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
<ItemGroup>
<ProjectReference Include="..\src\System.Threading.Tasks.Dataflow.csproj">
- <SupportedFramework>net45;netcore45;wp8;wpa81;netcoreapp1.0;$(AllXamarinFrameworks)</SupportedFramework>
+ <SupportedFramework>net461;netcoreapp2.0;uap10.0.16299;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<!-- Since UAP and .NETCoreApp are package based we still want to enable
<ValidatePackageSuppression Include="TreatAsOutOfBox">
<Value>.NETCoreApp;UAP</Value>
</ValidatePackageSuppression>
+
+ <!-- Exclude TFMs that aren't supported by the package anymore from validation. -->
+ <ExcludeHarvestedSupportedFramework Include="netcoreapp1.0;netcoreapp1.1;netcore45;netcore451;netcore50;uap10.0;wp8;wpa81;net45;net451;net46" />
</ItemGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
</Project>
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>netstandard2.1;netstandard2.0;netstandard1.0;netstandard1.1;net461</TargetFrameworks>
+ <TargetFrameworks>netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Threading.Tasks.Dataflow.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
- <Compile Include="System.Threading.Tasks.Dataflow.netstandard21.cs" />
+ <Compile Include="System.Threading.Tasks.Dataflow.netstandard21.cs"
+ Condition="'$(TargetFramework)' == 'netstandard2.1'" />
</ItemGroup>
</Project>
using System.Runtime.CompilerServices;
using System.Threading.Tasks.Dataflow.Internal;
-#if USE_INTERNAL_THREADING
-using System.Threading.Tasks.Dataflow.Internal.Threading;
-#endif
-
namespace System.Threading.Tasks.Dataflow
{
/// <summary>
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, Completion, state => ((TargetCore<TInput>)state!).Complete(exception: null, dropPendingMessages: true), _defaultTarget);
}
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
Debug.Assert((_spscTarget != null) ^ (_defaultTarget != null), "One and only one of the two targets must be non-null after construction");
}
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, _source.Completion, state => ((BatchBlockTargetCore)state!).Complete(exception: null, dropPendingMessages: true, releaseReservedMessages: false), _target);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Blocks/Member[@name="Complete"]/*' />
_nonGreedyState!.TaskForInputProcessing = new Task(thisBatchTarget => ((BatchBlockTargetCore)thisBatchTarget!).ProcessMessagesLoopCore(), this,
Common.GetCreationOptionsForTask(isReplacementReplica));
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
_owningBatch, _nonGreedyState.TaskForInputProcessing, DataflowEtwProvider.TaskLaunchedReason.ProcessingInputMessages,
_messages.Count + _nonGreedyState.PostponedMessages.Count);
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(_nonGreedyState.TaskForInputProcessing, _dataflowBlockOptions.TaskScheduler);
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, _source.Completion, state => ((BatchedJoinBlock<T1, T2>)state!).CompleteEachTarget(), this);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <summary>Gets the size of the batches generated by this <see cref="BatchedJoinBlock{T1,T2}"/>.</summary>
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, _source.Completion, state => ((BatchedJoinBlock<T1, T2, T3>)state!).CompleteEachTarget(), this);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <summary>Gets the size of the batches generated by this <see cref="BatchedJoinBlock{T1,T2,T3}"/>.</summary>
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, _source.Completion, state => ((BroadcastBlock<T>)state!).Complete(), this);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Blocks/Member[@name="Complete"]/*' />
new Task(state => ((BroadcastBlock<T>)state!).ConsumeMessagesLoopCore(), this,
Common.GetCreationOptionsForTask(isReplacementReplica));
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
this, _boundingState.TaskForInputProcessing, DataflowEtwProvider.TaskLaunchedReason.ProcessingInputMessages,
_boundingState.PostponedMessages.Count);
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(_boundingState.TaskForInputProcessing, _source.DataflowBlockOptions.TaskScheduler);
_taskForOutputProcessing = new Task(thisSourceCore => ((BroadcastingSourceCore<TOutput>)thisSourceCore!).OfferMessagesLoopCore(), this,
Common.GetCreationOptionsForTask(isReplacementReplica));
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.TaskLaunchedForMessageHandling(
_owningSource, _taskForOutputProcessing, DataflowEtwProvider.TaskLaunchedReason.OfferingOutputMessages, _messages.Count);
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(_taskForOutputProcessing, _dataflowBlockOptions.TaskScheduler);
// Now that the completion task is completed, we may propagate completion to the linked targets
_targetRegistry.PropagateCompletion(linkedTargets);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCompleted(_owningSource);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="LinkTo"]/*' />
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, _source.Completion, owningSource => ((BufferBlock<T>)owningSource!).Complete(), this);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Targets/Member[@name="OfferMessage"]/*' />
new Task(state => ((BufferBlock<T>)state!).ConsumeMessagesLoopCore(), this,
Common.GetCreationOptionsForTask(isReplacementReplica));
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
this, _boundingState.TaskForInputProcessing, DataflowEtwProvider.TaskLaunchedReason.ProcessingInputMessages,
_boundingState.PostponedMessages.Count);
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(_boundingState.TaskForInputProcessing, _source.DataflowBlockOptions.TaskScheduler);
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, _source.Completion, state => ((JoinBlock<T1, T2>)state!)._sharedResources.CompleteEachTarget(), this);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="LinkTo"]/*' />
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, _source.Completion, state => ((JoinBlock<T1, T2, T3>)state!)._sharedResources.CompleteEachTarget(), this);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="LinkTo"]/*' />
_taskForInputProcessing = new Task(thisSharedResources => ((JoinBlockTargetSharedResources)thisSharedResources!).ProcessMessagesLoopCore(), this,
Common.GetCreationOptionsForTask(isReplacementReplica));
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
_ownerJoin, _taskForInputProcessing, DataflowEtwProvider.TaskLaunchedReason.ProcessingInputMessages,
_targets.Max(t => t.NumberOfMessagesAvailableOrPostponed));
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(_taskForInputProcessing, _dataflowBlockOptions.TaskScheduler);
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, Completion, state => ((TargetCore<TInput>)state!).Complete(exception: null, dropPendingMessages: true), _target);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <summary>Processes the message with a user-provided transform function that returns a TOutput.</summary>
// Handle async cancellation requests by declining on the target
Common.WireCancellationToComplete(
dataflowBlockOptions.CancellationToken, Completion, state => ((TargetCore<TInput>)state!).Complete(exception: null, dropPendingMessages: true), _target);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <summary>Processes the message with a user-provided transform function that returns an enumerable.</summary>
dataflowBlockOptions.CancellationToken, _lazyCompletionTaskSource.Task, state => ((WriteOnceBlock<T>)state!).Complete(), this);
}
}
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
}
-#endif
}
/// <summary>Asynchronously completes the block on another task.</summary>
var taskForOutputProcessing = new Task(state => ((WriteOnceBlock<T>)state!).OfferToTargetsAndCompleteBlock(), this,
Common.GetCreationOptionsForTask());
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.TaskLaunchedForMessageHandling(
this, taskForOutputProcessing, DataflowEtwProvider.TaskLaunchedReason.OfferingOutputMessages, _header.IsValid ? 1 : 0);
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(taskForOutputProcessing, _dataflowBlockOptions.TaskScheduler);
// Now that the completion task is completed, we may propagate completion to the linked targets
_targetRegistry.PropagateCompletion(linkedTargets);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCompleted(this);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Blocks/Member[@name="Fault"]/*' />
using System.Collections;
using System.Runtime.ExceptionServices;
-#if USE_INTERNAL_THREADING
-using System.Threading.Tasks.Dataflow.Internal.Threading;
-#endif
-
namespace System.Threading.Tasks.Dataflow.Internal
{
/// <summary>Internal helper utilities.</summary>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-// ConcurrentQueue.cs
-//
-//
-// A lock-free, concurrent queue primitive, and its associated debugger view type.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-#nullable disable // old copy used only for netstandard1.0 build
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Security;
-using System.Threading;
-
-namespace System.Threading.Tasks.Dataflow.Internal.Collections
-{
- /// <summary>
- /// Represents a thread-safe first-in, first-out collection of objects.
- /// </summary>
- /// <typeparam name="T">Specifies the type of elements in the queue.</typeparam>
- /// <remarks>
- /// All public and protected members of <see cref="ConcurrentQueue{T}"/> are thread-safe and may be used
- /// concurrently from multiple threads.
- /// </remarks>
- [DebuggerDisplay("Count = {Count}")]
- [DebuggerTypeProxy(typeof(SystemCollectionsConcurrent_ProducerConsumerCollectionDebugView<>))]
- internal class ConcurrentQueue<T> : IProducerConsumerCollection<T>
- {
- private volatile Segment _head;
- private volatile Segment _tail;
- private const int SEGMENT_SIZE = 32;
- //number of snapshot takers, GetEnumerator(), ToList() and ToArray() operations take snapshot.
- internal volatile int _numSnapshotTakers;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ConcurrentQueue{T}"/> class.
- /// </summary>
- public ConcurrentQueue()
- {
- _head = _tail = new Segment(0, this);
- }
-
- /// <summary>
- /// Initializes the contents of the queue from an existing collection.
- /// </summary>
- /// <param name="collection">A collection from which to copy elements.</param>
- private void InitializeFromCollection(IEnumerable<T> collection)
- {
- Segment localTail = new Segment(0, this);//use this local variable to avoid the extra volatile read/write. this is safe because it is only called from ctor
- _head = localTail;
-
- int index = 0;
- foreach (T element in collection)
- {
- Debug.Assert(index >= 0 && index < SEGMENT_SIZE);
- localTail.UnsafeAdd(element);
- index++;
-
- if (index >= SEGMENT_SIZE)
- {
- localTail = localTail.UnsafeGrow();
- index = 0;
- }
- }
-
- _tail = localTail;
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ConcurrentQueue{T}"/>
- /// class that contains elements copied from the specified collection
- /// </summary>
- /// <param name="collection">The collection whose elements are copied to the new <see
- /// cref="ConcurrentQueue{T}"/>.</param>
- /// <exception cref="System.ArgumentNullException">The <paramref name="collection"/> argument is
- /// null.</exception>
- public ConcurrentQueue(IEnumerable<T> collection)
- {
- if (collection == null)
- {
- throw new ArgumentNullException(nameof(collection));
- }
-
- InitializeFromCollection(collection);
- }
-
- /// <summary>
- /// Copies the elements of the <see cref="System.Collections.ICollection"/> to an <see
- /// cref="System.Array"/>, starting at a particular
- /// <see cref="System.Array"/> index.
- /// </summary>
- /// <param name="array">The one-dimensional <see cref="System.Array">Array</see> that is the
- /// destination of the elements copied from the
- /// <see cref="ConcurrentQueue{T}"/>. The <see
- /// cref="System.Array">Array</see> must have zero-based indexing.</param>
- /// <param name="index">The zero-based index in <paramref name="array"/> at which copying
- /// begins.</param>
- /// <exception cref="ArgumentNullException"><paramref name="array"/> is a null reference (Nothing in
- /// Visual Basic).</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than
- /// zero.</exception>
- /// <exception cref="ArgumentException">
- /// <paramref name="array"/> is multidimensional. -or-
- /// <paramref name="array"/> does not have zero-based indexing. -or-
- /// <paramref name="index"/> is equal to or greater than the length of the <paramref name="array"/>
- /// -or- The number of elements in the source <see cref="System.Collections.ICollection"/> is
- /// greater than the available space from <paramref name="index"/> to the end of the destination
- /// <paramref name="array"/>. -or- The type of the source <see
- /// cref="System.Collections.ICollection"/> cannot be cast automatically to the type of the
- /// destination <paramref name="array"/>.
- /// </exception>
- void ICollection.CopyTo(Array array, int index)
- {
- // Validate arguments.
- if (array == null)
- {
- throw new ArgumentNullException(nameof(array));
- }
-
- // We must be careful not to corrupt the array, so we will first accumulate an
- // internal list of elements that we will then copy to the array. This requires
- // some extra allocation, but is necessary since we don't know up front whether
- // the array is sufficiently large to hold the stack's contents.
- ((ICollection)ToList()).CopyTo(array, index);
- }
-
- /// <summary>
- /// Gets a value indicating whether access to the <see cref="System.Collections.ICollection"/> is
- /// synchronized with the SyncRoot.
- /// </summary>
- /// <value>true if access to the <see cref="System.Collections.ICollection"/> is synchronized
- /// with the SyncRoot; otherwise, false. For <see cref="ConcurrentQueue{T}"/>, this property always
- /// returns false.</value>
- bool ICollection.IsSynchronized
- {
- // Gets a value indicating whether access to this collection is synchronized. Always returns
- // false. The reason is subtle. While access is in face thread safe, it's not the case that
- // locking on the SyncRoot would have prevented concurrent pushes and pops, as this property
- // would typically indicate; that's because we internally use CAS operations vs. true locks.
- get { return false; }
- }
-
-
- /// <summary>
- /// Gets an object that can be used to synchronize access to the <see
- /// cref="System.Collections.ICollection"/>. This property is not supported.
- /// </summary>
- /// <exception cref="System.NotSupportedException">The SyncRoot property is not supported.</exception>
- object ICollection.SyncRoot
- {
- get
- {
- throw new NotSupportedException(SR.ConcurrentCollection_SyncRoot_NotSupported);
- }
- }
-
- /// <summary>
- /// Returns an enumerator that iterates through a collection.
- /// </summary>
- /// <returns>An <see cref="System.Collections.IEnumerator"/> that can be used to iterate through the collection.</returns>
- IEnumerator IEnumerable.GetEnumerator()
- {
- return ((IEnumerable<T>)this).GetEnumerator();
- }
-
- /// <summary>
- /// Attempts to add an object to the <see
- /// cref="IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">The object to add to the <see
- /// cref="IProducerConsumerCollection{T}"/>. The value can be a null
- /// reference (Nothing in Visual Basic) for reference types.
- /// </param>
- /// <returns>true if the object was added successfully; otherwise, false.</returns>
- /// <remarks>For <see cref="ConcurrentQueue{T}"/>, this operation will always add the object to the
- /// end of the <see cref="ConcurrentQueue{T}"/>
- /// and return true.</remarks>
- bool IProducerConsumerCollection<T>.TryAdd(T item)
- {
- Enqueue(item);
- return true;
- }
-
- /// <summary>
- /// Attempts to remove and return an object from the <see
- /// cref="IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">
- /// When this method returns, if the operation was successful, <paramref name="item"/> contains the
- /// object removed. If no object was available to be removed, the value is unspecified.
- /// </param>
- /// <returns>true if an element was removed and returned successfully; otherwise, false.</returns>
- /// <remarks>For <see cref="ConcurrentQueue{T}"/>, this operation will attempt to remove the object
- /// from the beginning of the <see cref="ConcurrentQueue{T}"/>.
- /// </remarks>
- bool IProducerConsumerCollection<T>.TryTake(out T item)
- {
- return TryDequeue(out item);
- }
-
- /// <summary>
- /// Gets a value that indicates whether the <see cref="ConcurrentQueue{T}"/> is empty.
- /// </summary>
- /// <value>true if the <see cref="ConcurrentQueue{T}"/> is empty; otherwise, false.</value>
- /// <remarks>
- /// For determining whether the collection contains any items, use of this property is recommended
- /// rather than retrieving the number of items from the <see cref="Count"/> property and comparing it
- /// to 0. However, as this collection is intended to be accessed concurrently, it may be the case
- /// that another thread will modify the collection after <see cref="IsEmpty"/> returns, thus invalidating
- /// the result.
- /// </remarks>
- public bool IsEmpty
- {
- get
- {
- Segment head = _head;
- if (!head.IsEmpty)
- //fast route 1:
- //if current head is not empty, then queue is not empty
- return false;
- else if (head.Next == null)
- //fast route 2:
- //if current head is empty and it's the last segment
- //then queue is empty
- return true;
- else
- //slow route:
- //current head is empty and it is NOT the last segment,
- //it means another thread is growing new segment
- {
- SpinWait spin = default;
- while (head.IsEmpty)
- {
- if (head.Next == null)
- return true;
-
- spin.SpinOnce();
- head = _head;
- }
- return false;
- }
- }
- }
-
- /// <summary>
- /// Copies the elements stored in the <see cref="ConcurrentQueue{T}"/> to a new array.
- /// </summary>
- /// <returns>A new array containing a snapshot of elements copied from the <see
- /// cref="ConcurrentQueue{T}"/>.</returns>
- public T[] ToArray()
- {
- return ToList().ToArray();
- }
-
- /// <summary>
- /// Copies the <see cref="ConcurrentQueue{T}"/> elements to a new <see
- /// cref="System.Collections.Generic.List{T}"/>.
- /// </summary>
- /// <returns>A new <see cref="System.Collections.Generic.List{T}"/> containing a snapshot of
- /// elements copied from the <see cref="ConcurrentQueue{T}"/>.</returns>
- private List<T> ToList()
- {
- // Increments the number of active snapshot takers. This increment must happen before the snapshot is
- // taken. At the same time, Decrement must happen after list copying is over. Only in this way, can it
- // eliminate race condition when Segment.TryRemove() checks whether _numSnapshotTakers == 0.
- Interlocked.Increment(ref _numSnapshotTakers);
-
- List<T> list = new List<T>();
- try
- {
- //store head and tail positions in buffer,
- Segment head, tail;
- int headLow, tailHigh;
- GetHeadTailPositions(out head, out tail, out headLow, out tailHigh);
-
- if (head == tail)
- {
- head.AddToList(list, headLow, tailHigh);
- }
- else
- {
- head.AddToList(list, headLow, SEGMENT_SIZE - 1);
- Segment curr = head.Next;
- while (curr != tail)
- {
- curr.AddToList(list, 0, SEGMENT_SIZE - 1);
- curr = curr.Next;
- }
- //Add tail segment
- tail.AddToList(list, 0, tailHigh);
- }
- }
- finally
- {
- // This Decrement must happen after copying is over.
- Interlocked.Decrement(ref _numSnapshotTakers);
- }
- return list;
- }
-
- /// <summary>
- /// Store the position of the current head and tail positions.
- /// </summary>
- /// <param name="head">return the head segment</param>
- /// <param name="tail">return the tail segment</param>
- /// <param name="headLow">return the head offset, value range [0, SEGMENT_SIZE]</param>
- /// <param name="tailHigh">return the tail offset, value range [-1, SEGMENT_SIZE-1]</param>
- private void GetHeadTailPositions(out Segment head, out Segment tail,
- out int headLow, out int tailHigh)
- {
- head = _head;
- tail = _tail;
- headLow = head.Low;
- tailHigh = tail.High;
- SpinWait spin = default;
-
- //we loop until the observed values are stable and sensible.
- //This ensures that any update order by other methods can be tolerated.
- while (
- //if head and tail changed, retry
- head != _head || tail != _tail
- //if low and high pointers, retry
- || headLow != head.Low || tailHigh != tail.High
- //if head jumps ahead of tail because of concurrent grow and dequeue, retry
- || head._index > tail._index)
- {
- spin.SpinOnce();
- head = _head;
- tail = _tail;
- headLow = head.Low;
- tailHigh = tail.High;
- }
- }
-
-
- /// <summary>
- /// Gets the number of elements contained in the <see cref="ConcurrentQueue{T}"/>.
- /// </summary>
- /// <value>The number of elements contained in the <see cref="ConcurrentQueue{T}"/>.</value>
- /// <remarks>
- /// For determining whether the collection contains any items, use of the <see cref="IsEmpty"/>
- /// property is recommended rather than retrieving the number of items from the <see cref="Count"/>
- /// property and comparing it to 0.
- /// </remarks>
- public int Count
- {
- get
- {
- //store head and tail positions in buffer,
- Segment head, tail;
- int headLow, tailHigh;
- GetHeadTailPositions(out head, out tail, out headLow, out tailHigh);
-
- if (head == tail)
- {
- return tailHigh - headLow + 1;
- }
-
- //head segment
- int count = SEGMENT_SIZE - headLow;
-
- //middle segment(s), if any, are full.
- //We don't deal with overflow to be consistent with the behavior of generic types in CLR.
- count += SEGMENT_SIZE * ((int)(tail._index - head._index - 1));
-
- //tail segment
- count += tailHigh + 1;
-
- return count;
- }
- }
-
-
- /// <summary>
- /// Copies the <see cref="ConcurrentQueue{T}"/> elements to an existing one-dimensional <see
- /// cref="System.Array">Array</see>, starting at the specified array index.
- /// </summary>
- /// <param name="array">The one-dimensional <see cref="System.Array">Array</see> that is the
- /// destination of the elements copied from the
- /// <see cref="ConcurrentQueue{T}"/>. The <see cref="System.Array">Array</see> must have zero-based
- /// indexing.</param>
- /// <param name="index">The zero-based index in <paramref name="array"/> at which copying
- /// begins.</param>
- /// <exception cref="ArgumentNullException"><paramref name="array"/> is a null reference (Nothing in
- /// Visual Basic).</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than
- /// zero.</exception>
- /// <exception cref="ArgumentException"><paramref name="index"/> is equal to or greater than the
- /// length of the <paramref name="array"/>
- /// -or- The number of elements in the source <see cref="ConcurrentQueue{T}"/> is greater than the
- /// available space from <paramref name="index"/> to the end of the destination <paramref
- /// name="array"/>.
- /// </exception>
- public void CopyTo(T[] array, int index)
- {
- if (array == null)
- {
- throw new ArgumentNullException(nameof(array));
- }
-
- // We must be careful not to corrupt the array, so we will first accumulate an
- // internal list of elements that we will then copy to the array. This requires
- // some extra allocation, but is necessary since we don't know up front whether
- // the array is sufficiently large to hold the stack's contents.
- ToList().CopyTo(array, index);
- }
-
-
- /// <summary>
- /// Returns an enumerator that iterates through the <see
- /// cref="ConcurrentQueue{T}"/>.
- /// </summary>
- /// <returns>An enumerator for the contents of the <see
- /// cref="ConcurrentQueue{T}"/>.</returns>
- /// <remarks>
- /// The enumeration represents a moment-in-time snapshot of the contents
- /// of the queue. It does not reflect any updates to the collection after
- /// <see cref="GetEnumerator()"/> was called. The enumerator is safe to use
- /// concurrently with reads from and writes to the queue.
- /// </remarks>
- public IEnumerator<T> GetEnumerator()
- {
- // Increments the number of active snapshot takers. This increment must happen before the snapshot is
- // taken. At the same time, Decrement must happen after the enumeration is over. Only in this way, can it
- // eliminate race condition when Segment.TryRemove() checks whether _numSnapshotTakers == 0.
- Interlocked.Increment(ref _numSnapshotTakers);
-
- // Takes a snapshot of the queue.
- // A design flaw here: if a Thread.Abort() happens, we cannot decrement _numSnapshotTakers. But we cannot
- // wrap the following with a try/finally block, otherwise the decrement will happen before the yield return
- // statements in the GetEnumerator (head, tail, headLow, tailHigh) method.
- Segment head, tail;
- int headLow, tailHigh;
- GetHeadTailPositions(out head, out tail, out headLow, out tailHigh);
-
- //If we put yield-return here, the iterator will be lazily evaluated. As a result a snapshot of
- // the queue is not taken when GetEnumerator is initialized but when MoveNext() is first called.
- // This is inconsistent with existing generic collections. In order to prevent it, we capture the
- // value of _head in a buffer and call out to a helper method.
- //The old way of doing this was to return the ToList().GetEnumerator(), but ToList() was an
- // unnecessary performance hit.
- return GetEnumerator(head, tail, headLow, tailHigh);
- }
-
- /// <summary>
- /// Helper method of GetEnumerator to separate out yield return statement, and prevent lazy evaluation.
- /// </summary>
- private IEnumerator<T> GetEnumerator(Segment head, Segment tail, int headLow, int tailHigh)
- {
- try
- {
- SpinWait spin = default;
-
- if (head == tail)
- {
- for (int i = headLow; i <= tailHigh; i++)
- {
- // If the position is reserved by an Enqueue operation, but the value is not written into,
- // spin until the value is available.
- spin.Reset();
- while (!head._state[i]._value)
- {
- spin.SpinOnce();
- }
- yield return head._array[i];
- }
- }
- else
- {
- //iterate on head segment
- for (int i = headLow; i < SEGMENT_SIZE; i++)
- {
- // If the position is reserved by an Enqueue operation, but the value is not written into,
- // spin until the value is available.
- spin.Reset();
- while (!head._state[i]._value)
- {
- spin.SpinOnce();
- }
- yield return head._array[i];
- }
- //iterate on middle segments
- Segment curr = head.Next;
- while (curr != tail)
- {
- for (int i = 0; i < SEGMENT_SIZE; i++)
- {
- // If the position is reserved by an Enqueue operation, but the value is not written into,
- // spin until the value is available.
- spin.Reset();
- while (!curr._state[i]._value)
- {
- spin.SpinOnce();
- }
- yield return curr._array[i];
- }
- curr = curr.Next;
- }
-
- //iterate on tail segment
- for (int i = 0; i <= tailHigh; i++)
- {
- // If the position is reserved by an Enqueue operation, but the value is not written into,
- // spin until the value is available.
- spin.Reset();
- while (!tail._state[i]._value)
- {
- spin.SpinOnce();
- }
- yield return tail._array[i];
- }
- }
- }
- finally
- {
- // This Decrement must happen after the enumeration is over.
- Interlocked.Decrement(ref _numSnapshotTakers);
- }
- }
-
- /// <summary>
- /// Adds an object to the end of the <see cref="ConcurrentQueue{T}"/>.
- /// </summary>
- /// <param name="item">The object to add to the end of the <see
- /// cref="ConcurrentQueue{T}"/>. The value can be a null reference
- /// (Nothing in Visual Basic) for reference types.
- /// </param>
- public void Enqueue(T item)
- {
- SpinWait spin = default;
- while (true)
- {
- Segment tail = _tail;
- if (tail.TryAppend(item))
- return;
- spin.SpinOnce();
- }
- }
-
-
- /// <summary>
- /// Attempts to remove and return the object at the beginning of the <see
- /// cref="ConcurrentQueue{T}"/>.
- /// </summary>
- /// <param name="result">
- /// When this method returns, if the operation was successful, <paramref name="result"/> contains the
- /// object removed. If no object was available to be removed, the value is unspecified.
- /// </param>
- /// <returns>true if an element was removed and returned from the beginning of the <see
- /// cref="ConcurrentQueue{T}"/>
- /// successfully; otherwise, false.</returns>
- public bool TryDequeue(out T result)
- {
- while (!IsEmpty)
- {
- Segment head = _head;
- if (head.TryRemove(out result))
- return true;
- //since method IsEmpty spins, we don't need to spin in the while loop
- }
- result = default(T);
- return false;
- }
-
- /// <summary>
- /// Attempts to return an object from the beginning of the <see cref="ConcurrentQueue{T}"/>
- /// without removing it.
- /// </summary>
- /// <param name="result">When this method returns, <paramref name="result"/> contains an object from
- /// the beginning of the <see cref="ConcurrentQueue{T}"/> or an
- /// unspecified value if the operation failed.</param>
- /// <returns>true if and object was returned successfully; otherwise, false.</returns>
- public bool TryPeek(out T result)
- {
- Interlocked.Increment(ref _numSnapshotTakers);
-
- while (!IsEmpty)
- {
- Segment head = _head;
- if (head.TryPeek(out result))
- {
- Interlocked.Decrement(ref _numSnapshotTakers);
- return true;
- }
- //since method IsEmpty spins, we don't need to spin in the while loop
- }
- result = default(T);
- Interlocked.Decrement(ref _numSnapshotTakers);
- return false;
- }
-
-
- /// <summary>
- /// private class for ConcurrentQueue.
- /// a queue is a linked list of small arrays, each node is called a segment.
- /// A segment contains an array, a pointer to the next segment, and _low, _high indices recording
- /// the first and last valid elements of the array.
- /// </summary>
- private sealed class Segment
- {
- //we define two volatile arrays: _array and _state. Note that the accesses to the array items
- //do not get volatile treatment. But we don't need to worry about loading adjacent elements or
- //store/load on adjacent elements would suffer reordering.
- // - Two stores: these are at risk, but CLRv2 memory model guarantees store-release hence we are safe.
- // - Two loads: because one item from two volatile arrays are accessed, the loads of the array references
- // are sufficient to prevent reordering of the loads of the elements.
- internal volatile T[] _array;
-
- // For each entry in _array, the corresponding entry in _state indicates whether this position contains
- // a valid value. _state is initially all false.
- internal volatile VolatileBool[] _state;
-
- //pointer to the next segment. null if the current segment is the last segment
- private volatile Segment _next;
-
- //We use this zero based index to track how many segments have been created for the queue, and
- //to compute how many active segments are there currently.
- // * The number of currently active segments is : _tail._index - _head._index + 1;
- // * _index is incremented with every Segment.Grow operation. We use Int64 type, and we can safely
- // assume that it never overflows. To overflow, we need to do 2^63 increments, even at a rate of 4
- // billion (2^32) increments per second, it takes 2^31 seconds, which is about 64 years.
- internal readonly long _index;
-
- //indices of where the first and last valid values
- // - _low points to the position of the next element to pop from this segment, range [0, infinity)
- // _low >= SEGMENT_SIZE implies the segment is disposable
- // - _high points to the position of the latest pushed element, range [-1, infinity)
- // _high == -1 implies the segment is new and empty
- // _high >= SEGMENT_SIZE-1 means this segment is ready to grow.
- // and the thread who sets _high to SEGMENT_SIZE-1 is responsible to grow the segment
- // - Math.Min(_low, SEGMENT_SIZE) > Math.Min(_high, SEGMENT_SIZE-1) implies segment is empty
- // - initially _low =0 and _high=-1;
- private volatile int _low;
- private volatile int _high;
-
- private volatile ConcurrentQueue<T> _source;
-
- /// <summary>
- /// Create and initialize a segment with the specified index.
- /// </summary>
- internal Segment(long index, ConcurrentQueue<T> source)
- {
- _array = new T[SEGMENT_SIZE];
- _state = new VolatileBool[SEGMENT_SIZE]; //all initialized to false
- _high = -1;
- Debug.Assert(index >= 0);
- _index = index;
- _source = source;
- }
-
- /// <summary>
- /// return the next segment
- /// </summary>
- internal Segment Next
- {
- get { return _next; }
- }
-
-
- /// <summary>
- /// return true if the current segment is empty (doesn't have any element available to dequeue,
- /// false otherwise
- /// </summary>
- internal bool IsEmpty
- {
- get { return (Low > High); }
- }
-
- /// <summary>
- /// Add an element to the tail of the current segment
- /// exclusively called by ConcurrentQueue.InitializedFromCollection
- /// InitializeFromCollection is responsible to guarantee that there is no index overflow,
- /// and there is no contention
- /// </summary>
- /// <param name="value"></param>
- internal void UnsafeAdd(T value)
- {
- Debug.Assert(_high < SEGMENT_SIZE - 1);
- _high++;
- _array[_high] = value;
- _state[_high]._value = true;
- }
-
- /// <summary>
- /// Create a new segment and append to the current one
- /// Does not update the _tail pointer
- /// exclusively called by ConcurrentQueue.InitializedFromCollection
- /// InitializeFromCollection is responsible to guarantee that there is no index overflow,
- /// and there is no contention
- /// </summary>
- /// <returns>the reference to the new Segment</returns>
- internal Segment UnsafeGrow()
- {
- Debug.Assert(_high >= SEGMENT_SIZE - 1);
- Segment newSegment = new Segment(_index + 1, _source); //_index is Int64, we don't need to worry about overflow
- _next = newSegment;
- return newSegment;
- }
-
- /// <summary>
- /// Create a new segment and append to the current one
- /// Update the _tail pointer
- /// This method is called when there is no contention
- /// </summary>
- internal void Grow()
- {
- //no CAS is needed, since there is no contention (other threads are blocked, busy waiting)
- Segment newSegment = new Segment(_index + 1, _source); //_index is Int64, we don't need to worry about overflow
- _next = newSegment;
- Debug.Assert(_source._tail == this);
- _source._tail = _next;
- }
-
-
- /// <summary>
- /// Try to append an element at the end of this segment.
- /// </summary>
- /// <param name="value">the element to append</param>
- /// <returns>true if the element is appended, false if the current segment is full</returns>
- /// <remarks>if appending the specified element succeeds, and after which the segment is full,
- /// then grow the segment</remarks>
- internal bool TryAppend(T value)
- {
- //quickly check if _high is already over the boundary, if so, bail out
- if (_high >= SEGMENT_SIZE - 1)
- {
- return false;
- }
-
- //Now we will use a CAS to increment _high, and store the result in newhigh.
- //Depending on how many free spots left in this segment and how many threads are doing this Increment
- //at this time, the returning "newhigh" can be
- // 1) < SEGMENT_SIZE - 1 : we took a spot in this segment, and not the last one, just insert the value
- // 2) == SEGMENT_SIZE - 1 : we took the last spot, insert the value AND grow the segment
- // 3) > SEGMENT_SIZE - 1 : we failed to reserve a spot in this segment, we return false to
- // Queue.Enqueue method, telling it to try again in the next segment.
-
- int newhigh = SEGMENT_SIZE; //initial value set to be over the boundary
-
- //We need do Interlocked.Increment and value/state update in a finally block to ensure that they run
- //without interruption. This is to prevent anything from happening between them, and another dequeue
- //thread maybe spinning forever to wait for _state[] to be true;
- try
- { }
- finally
- {
- newhigh = Interlocked.Increment(ref _high);
- if (newhigh <= SEGMENT_SIZE - 1)
- {
- _array[newhigh] = value;
- _state[newhigh]._value = true;
- }
-
- //if this thread takes up the last slot in the segment, then this thread is responsible
- //to grow a new segment. Calling Grow must be in the finally block too for reliability reason:
- //if thread abort during Grow, other threads will be left busy spinning forever.
- if (newhigh == SEGMENT_SIZE - 1)
- {
- Grow();
- }
- }
-
- //if newhigh <= SEGMENT_SIZE-1, it means the current thread successfully takes up a spot
- return newhigh <= SEGMENT_SIZE - 1;
- }
-
-
- /// <summary>
- /// try to remove an element from the head of current segment
- /// </summary>
- /// <param name="result">The result.</param>
- /// <returns>return false only if the current segment is empty</returns>
- internal bool TryRemove(out T result)
- {
- SpinWait spin = default;
- int lowLocal = Low, highLocal = High;
- while (lowLocal <= highLocal)
- {
- //try to update _low
- if (Interlocked.CompareExchange(ref _low, lowLocal + 1, lowLocal) == lowLocal)
- {
- //if the specified value is not available (this spot is taken by a push operation,
- // but the value is not written into yet), then spin
- SpinWait spinLocal = default;
- while (!_state[lowLocal]._value)
- {
- spinLocal.SpinOnce();
- }
- result = _array[lowLocal];
-
- // If there is no other thread taking snapshot (GetEnumerator(), ToList(), etc), reset the deleted entry to null.
- // It is ok if after this conditional check _numSnapshotTakers becomes > 0, because new snapshots won't include
- // the deleted entry at _array[lowLocal].
- if (_source._numSnapshotTakers <= 0)
- {
- _array[lowLocal] = default(T); //release the reference to the object.
- }
-
- //if the current thread sets _low to SEGMENT_SIZE, which means the current segment becomes
- //disposable, then this thread is responsible to dispose this segment, and reset _head
- if (lowLocal + 1 >= SEGMENT_SIZE)
- {
- // Invariant: we only dispose the current _head, not any other segment
- // In usual situation, disposing a segment is simply setting _head to _head._next
- // But there is one special case, where _head and _tail points to the same and ONLY
- //segment of the queue: Another thread A is doing Enqueue and finds that it needs to grow,
- //while the *current* thread is doing *this* Dequeue operation, and finds that it needs to
- //dispose the current (and ONLY) segment. Then we need to wait till thread A finishes its
- //Grow operation, this is the reason of having the following while loop
- spinLocal = default;
- while (_next == null)
- {
- spinLocal.SpinOnce();
- }
- Debug.Assert(_source._head == this);
- _source._head = _next;
- }
- return true;
- }
- else
- {
- //CAS failed due to contention: spin briefly and retry
- spin.SpinOnce();
- lowLocal = Low; highLocal = High;
- }
- }//end of while
- result = default(T);
- return false;
- }
-
- /// <summary>
- /// try to peek the current segment
- /// </summary>
- /// <param name="result">holds the return value of the element at the head position,
- /// value set to default(T) if there is no such an element</param>
- /// <returns>true if there are elements in the current segment, false otherwise</returns>
- internal bool TryPeek(out T result)
- {
- result = default(T);
- int lowLocal = Low;
- if (lowLocal > High)
- return false;
- SpinWait spin = default;
- while (!_state[lowLocal]._value)
- {
- spin.SpinOnce();
- }
- result = _array[lowLocal];
- return true;
- }
-
- /// <summary>
- /// Adds part or all of the current segment into a List.
- /// </summary>
- /// <param name="list">the list to which to add</param>
- /// <param name="start">the start position</param>
- /// <param name="end">the end position</param>
- internal void AddToList(List<T> list, int start, int end)
- {
- for (int i = start; i <= end; i++)
- {
- SpinWait spin = default;
- while (!_state[i]._value)
- {
- spin.SpinOnce();
- }
- list.Add(_array[i]);
- }
- }
-
- /// <summary>
- /// return the position of the head of the current segment
- /// Value range [0, SEGMENT_SIZE], if it's SEGMENT_SIZE, it means this segment is exhausted and thus empty
- /// </summary>
- internal int Low
- {
- get
- {
- return Math.Min(_low, SEGMENT_SIZE);
- }
- }
-
- /// <summary>
- /// return the logical position of the tail of the current segment
- /// Value range [-1, SEGMENT_SIZE-1]. When it's -1, it means this is a new segment and has no element yet
- /// </summary>
- internal int High
- {
- get
- {
- //if _high > SEGMENT_SIZE, it means it's out of range, we should return
- //SEGMENT_SIZE-1 as the logical position
- return Math.Min(_high, SEGMENT_SIZE - 1);
- }
- }
- }
- }//end of class Segment
-
- /// <summary>
- /// A wrapper struct for volatile bool, please note the copy of the struct it self will not be volatile
- /// for example this statement will not include in volatile operation volatileBool1 = volatileBool2 the jit will copy the struct and will ignore the volatile
- /// </summary>
- internal struct VolatileBool
- {
- public VolatileBool(bool value)
- {
- _value = value;
- }
- public volatile bool _value;
- }
-}
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security;
-#if FEATURE_TRACING
using System.Diagnostics.Tracing;
-#endif
namespace System.Threading.Tasks.Dataflow.Internal
{
-#if FEATURE_TRACING
/// <summary>Provides an event source for tracing Dataflow information.</summary>
[EventSource(
Name = "System.Threading.Tasks.Dataflow.DataflowEventSource",
}
#endregion
}
-#endif
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
-//
-// IProducerConsumerCollection.cs
-//
-//
-// A common interface for all concurrent collections.
-//
-// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
-#nullable disable // copy used only for netstandard1.0 build
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace System.Threading.Tasks.Dataflow.Internal.Collections
-{
- /// <summary>
- /// Defines methods to manipulate thread-safe collections intended for producer/consumer usage.
- /// </summary>
- /// <typeparam name="T">Specifies the type of elements in the collection.</typeparam>
- /// <remarks>
- /// All implementations of this interface must enable all members of this interface
- /// to be used concurrently from multiple threads.
- /// </remarks>
- internal interface IProducerConsumerCollection<T> : IEnumerable<T>, ICollection
- {
- /// <summary>
- /// Copies the elements of the <see cref="IProducerConsumerCollection{T}"/> to
- /// an
- /// <see cref="System.Array"/>, starting at a specified index.
- /// </summary>
- /// <param name="array">The one-dimensional <see cref="System.Array"/> that is the destination of
- /// the elements copied from the <see cref="IProducerConsumerCollection{T}"/>.
- /// The array must have zero-based indexing.</param>
- /// <param name="index">The zero-based index in <paramref name="array"/> at which copying
- /// begins.</param>
- /// <exception cref="ArgumentNullException"><paramref name="array"/> is a null reference (Nothing in
- /// Visual Basic).</exception>
- /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than
- /// zero.</exception>
- /// <exception cref="ArgumentException"><paramref name="index"/> is equal to or greater than the
- /// length of the <paramref name="array"/>
- /// -or- The number of elements in the source <see cref="ConcurrentQueue{T}"/> is greater than the
- /// available space from <paramref name="index"/> to the end of the destination <paramref
- /// name="array"/>.
- /// </exception>
- void CopyTo(T[] array, int index);
-
- /// <summary>
- /// Attempts to add an object to the <see
- /// cref="IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">The object to add to the <see
- /// cref="IProducerConsumerCollection{T}"/>.</param>
- /// <returns>true if the object was added successfully; otherwise, false.</returns>
- /// <exception cref="System.ArgumentException">The <paramref name="item"/> was invalid for this collection.</exception>
- bool TryAdd(T item);
-
- /// <summary>
- /// Attempts to remove and return an object from the <see cref="IProducerConsumerCollection{T}"/>.
- /// </summary>
- /// <param name="item">
- /// When this method returns, if the object was removed and returned successfully, <paramref
- /// name="item"/> contains the removed object. If no object was available to be removed, the value is
- /// unspecified.
- /// </param>
- /// <returns>true if an object was removed and returned successfully; otherwise, false.</returns>
- bool TryTake(out T item);
-
- /// <summary>
- /// Copies the elements contained in the <see cref="IProducerConsumerCollection{T}"/> to a new array.
- /// </summary>
- /// <returns>A new array containing the elements copied from the <see cref="IProducerConsumerCollection{T}"/>.</returns>
- T[] ToArray();
- }
-
-
- /// <summary>
- /// A debugger view of the IProducerConsumerCollection that makes it simple to browse the
- /// collection's contents at a point in time.
- /// </summary>
- /// <typeparam name="T">The type of elements stored within.</typeparam>
- internal sealed class SystemCollectionsConcurrent_ProducerConsumerCollectionDebugView<T>
- {
- private IProducerConsumerCollection<T> _collection; // The collection being viewed.
-
- /// <summary>
- /// Constructs a new debugger view object for the provided collection object.
- /// </summary>
- /// <param name="collection">A collection to browse in the debugger.</param>
- public SystemCollectionsConcurrent_ProducerConsumerCollectionDebugView(IProducerConsumerCollection<T> collection)
- {
- if (collection == null)
- {
- throw new ArgumentNullException(nameof(collection));
- }
-
- _collection = collection;
- }
-
- /// <summary>
- /// Returns a snapshot of the underlying collection's elements.
- /// </summary>
- [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
- public T[] Items
- {
- get { return _collection.ToArray(); }
- }
- }
-}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using System.Collections;
-#if USE_INTERNAL_CONCURRENT_COLLECTIONS
-using System.Threading.Tasks.Dataflow.Internal.Collections;
-#else
using System.Collections.Concurrent;
-#endif
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
_taskForOutputProcessing = new Task(thisSourceCore => ((SourceCore<TOutput>)thisSourceCore!).OfferMessagesLoopCore(), this,
Common.GetCreationOptionsForTask(isReplacementReplica));
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.TaskLaunchedForMessageHandling(
_owningSource, _taskForOutputProcessing, DataflowEtwProvider.TaskLaunchedReason.OfferingOutputMessages, _messages.Count);
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(_taskForOutputProcessing, _dataflowBlockOptions.TaskScheduler);
// Now that the completion task is completed, we may propagate completion to the linked targets
_targetRegistry.PropagateCompletion(linkedTargets);
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCompleted(_owningSource);
}
-#endif
}
/// <summary>Gets the object to display in the debugger display attribute.</summary>
{
// We won the race. This task is now the consumer.
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.TaskLaunchedForMessageHandling(
_owningTarget, newConsumer, DataflowEtwProvider.TaskLaunchedReason.ProcessingInputMessages, _messages.Count);
}
-#endif
// Start the task. In the erroneous case where the scheduler throws an exception,
// just allow it to propagate. Our other option would be to fault the block with
// seeing _activeTask as null and queueing a new consumer task even
// though the block has completed.
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockCompleted(_owningTarget);
}
-#endif
}
/// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Blocks/Member[@name="Completion"]/*' />
var taskForInputProcessing = new Task(thisTargetCore => ((TargetCore<TInput>)thisTargetCore!).ProcessMessagesLoopCore(), this,
Common.GetCreationOptionsForTask(repeat));
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
_owningTarget, taskForInputProcessing, DataflowEtwProvider.TaskLaunchedReason.ProcessingInputMessages,
_messages.Count + (_boundingState != null ? _boundingState.PostponedMessages.Count : 0));
}
-#endif
// Start the task handling scheduling exceptions
Exception? exception = Common.StartTaskSafe(taskForInputProcessing, _dataflowBlockOptions.TaskScheduler);
{
_completionSource.TrySetResult(default(VoidResult));
}
-#if FEATURE_TRACING
// We only want to do tracing for block completion if this target core represents the whole block.
// If it only represents a part of the block (i.e. there's a source associated with it as well),
// then we shouldn't log just for the first half of the block; the source half will handle logging.
{
etwLog.DataflowBlockCompleted(_owningTarget);
}
-#endif
}
/// <summary>Gets whether the target core is operating in a bounded mode.</summary>
// Increment the optimization counter if needed
Debug.Assert(_linksWithRemainingMessages >= 0, "_linksWithRemainingMessages must be non-negative at any time.");
if (node.RemainingMessages > 0) _linksWithRemainingMessages++;
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockLinking(_owningSource, target);
}
-#endif
}
/// <summary>Gets whether the registry contains a particular target.</summary>
// Decrement the optimization counter if needed
if (node.RemainingMessages == 0) _linksWithRemainingMessages--;
Debug.Assert(_linksWithRemainingMessages >= 0, "_linksWithRemainingMessages must be non-negative at any time.");
-#if FEATURE_TRACING
DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.DataflowBlockUnlinking(_owningSource, target);
}
-#endif
}
// If the target is to stay and we are counting the remaining messages for this link, decrement the counter
else if (node.RemainingMessages > 0)
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-#nullable disable // used only for netstandard1.0 build
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace System.Threading.Tasks.Dataflow.Internal.Threading
-{
- internal delegate void TimerCallback(object state);
-
- internal sealed class Timer : CancellationTokenSource, IDisposable
- {
- internal Timer(TimerCallback callback, object state, int dueTime, int period)
- {
- Debug.Assert(period == -1, "This stub implementation only supports dueTime.");
- Task.Delay(dueTime, Token).ContinueWith((t, s) =>
- {
- var tuple = (Tuple<TimerCallback, object>)s;
- tuple.Item1(tuple.Item2);
- }, Tuple.Create(callback, state), CancellationToken.None,
- TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion,
- TaskScheduler.Default);
- }
-
- public new void Dispose() { base.Cancel(); }
- }
-
- internal sealed class Thread
- {
- internal static bool Yield() { return true; }
- }
-
- internal delegate void WaitCallback(object state);
-
- internal sealed class ThreadPool
- {
- private static readonly SynchronizationContext _ctx = new SynchronizationContext();
-
- internal static void QueueUserWorkItem(WaitCallback callback, object state)
- {
- _ctx.Post(s =>
- {
- var tuple = (Tuple<WaitCallback, object>)s;
- tuple.Item1(tuple.Item2);
- }, Tuple.Create(callback, state));
- }
- }
-}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.1;netstandard2.0;netstandard1.0;netstandard1.1;net461</TargetFrameworks>
+ <TargetFrameworks>$(NetCoreAppCurrent);netstandard2.1;netstandard2.0;net461</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<Nullable>enable</Nullable>
</PropertyGroup>
- <!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
- <PropertyGroup>
- <DefineConstants Condition="'$(TargetFramework)' != 'netstandard1.0'">$(DefineConstants);FEATURE_TRACING</DefineConstants>
- <DefineConstants Condition="'$(TargetFramework)' == 'netstandard1.0'">$(DefineConstants);USE_INTERNAL_CONCURRENT_COLLECTIONS</DefineConstants>
- <DefineConstants Condition="'$(TargetFramework)' == 'netstandard1.0' or '$(TargetFramework)' == 'netstandard1.1'">$(DefineConstants);USE_INTERNAL_THREADING</DefineConstants>
- <PackageTargetFramework Condition="'$(TargetFramework)' == 'netstandard1.1'">netstandard1.1;portable-net45+win8+wpa81</PackageTargetFramework>
- </PropertyGroup>
<ItemGroup>
<Compile Include="Base\DataflowBlock.cs" />
<Compile Include="Base\DataflowBlockOptions.cs" />
<Compile Include="Base\DataflowLinkOptions.cs" />
<Compile Include="Base\DataflowMessageHeader.cs" />
<Compile Include="Base\DataflowMessageStatus.cs" />
+ <Compile Include="Base\DataflowBlock.IAsyncEnumerable.cs"
+ Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))" />
<Compile Include="Base\IDataflowBlock.cs" />
<Compile Include="Base\IPropagatorBlock.cs" />
<Compile Include="Base\IReceivableSourceBlock.cs" />
<Compile Include="Internal\TargetRegistry.cs" />
<Compile Include="$(CommonPath)Internal\Padding.cs"
Link="Common\Internal\Padding.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.0' or '$(TargetFramework)' == 'netstandard1.1'">
- <Compile Include="Internal\Threading.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.0'">
- <Compile Include="Internal\ConcurrentQueue.cs" />
- <Compile Include="Internal\IProducerConsumerCollection.cs" />
- </ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == '$(NetCoreAppCurrent)'">
- <Compile Include="Base\DataflowBlock.IAsyncEnumerable.cs" />
+ <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs"
+ Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))" />
</ItemGroup>
<ItemGroup>
<None Include="XmlDocs\CommonXmlDocComments.xml" />
- </ItemGroup>
- <ItemGroup>
<Content Include="XmlDocs\System.Threading.Tasks.Dataflow.xml" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' != '$(NetCoreAppCurrent)'">
- <Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
- </ItemGroup>
- <ItemGroup Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETCoreApp'">
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Reference Include="System.Collections" />
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System.Diagnostics.Tracing" />
<Reference Include="System.Threading.Thread" />
<Reference Include="System.Threading.ThreadPool" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.0' or '$(TargetFramework)' == 'netstandard1.1' or '$(TargetFramework)' == 'net461'">
+ <ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Diagnostics.Contracts" Version="$(SystemDiagnosticsContractsVersion)" />
<PackageReference Include="System.Dynamic.Runtime" Version="$(SystemDynamicRuntimeVersion)" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="$(SystemRuntimeSerializationPrimitivesVersion)" />