Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Consume/Consume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Consume
#endif
type = typeof(AsyncMethodBuilderAttribute);
type = typeof(CompilerLoweringPreserveAttribute);
type = typeof(IsClosedTypeAttribute);
#if !NET6_0 && !NET5_0
type = typeof(ObsoletedOSPlatformAttribute);
type = typeof(SupportedOSPlatformGuardAttribute);
Expand Down
38 changes: 38 additions & 0 deletions src/ConsumeCsPreview/ClosedHierarchy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace ConsumeCsPreview;

// Compile-only coverage for the C# `closed` modifier. The compiler emits
// IsClosedTypeAttribute on the closed type and
// CompilerFeatureRequiredAttribute("ClosedClasses") on its constructors,
// so this only compiles when both are polyfilled.

#region ClosedHierarchy

// Only types in this file can derive from JobStatus
closed class JobStatus;

sealed class Queued : JobStatus;

sealed class Running(int percentComplete) : JobStatus
{
public int PercentComplete => percentComplete;
}

sealed class Failed(string error) : JobStatus
{
public string Error => error;
}

static class ClosedHierarchy
{
// No default arm: the switch is exhaustive because every direct descendant of
// the closed JobStatus is handled. Without exhaustiveness this warns CS8509.
public static string Describe(JobStatus status) =>
status switch
{
Queued => "queued",
Running running => $"{running.PercentComplete}% complete",
Failed failed => $"failed: {failed.Error}"
};
}

#endregion
20 changes: 20 additions & 0 deletions src/ConsumeCsPreview/ConsumeCsPreview.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoWarn>$(NoWarn);PolyfillTargetsForNuget</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net461;net462;net47;net471;net472;net48;net481;net6.0-windows</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Memory" Condition="$(TargetFrameworkIdentifier) == '.NETStandard' or $(TargetFrameworkIdentifier) == '.NETFramework' or $(TargetFramework.StartsWith('netcoreapp'))" />
<PackageReference Include="System.ValueTuple" Condition="$(TargetFramework.StartsWith('net46'))" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Condition="$(TargetFramework.StartsWith('net4'))" />
<PackageReference Include="System.Net.Http" Condition="$(TargetFramework.StartsWith('net4'))" />
<PackageReference Include="System.Threading.Tasks.Extensions" Condition="$(TargetFramework) == 'netstandard2.0' or $(TargetFramework) == 'netcoreapp2.0' or $(TargetFrameworkIdentifier) == '.NETFramework'" />
<PackageReference Include="System.IO.Compression" Condition="$(TargetFrameworkIdentifier) == '.NETFramework'" />
<Compile Include="..\Consume\*.cs" />
</ItemGroup>
<Import Project="$(SolutionDir)\TestIncludes.targets" />
<Import Project="$(SolutionDir)\Polyfill\Polyfill.targets" />
</Project>
1 change: 1 addition & 0 deletions src/Polyfill.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<Project Path="ConsumeCsDefault/ConsumeCsDefault.csproj" />
<Project Path="ConsumeCsLatest/ConsumeCsLatest.csproj" />
<Project Path="ConsumeCsLatestMajor/ConsumeCsLatestMajor.csproj" />
<Project Path="ConsumeCsPreview/ConsumeCsPreview.csproj" />
<Project Path="ConsumeEmbeddedLib/ConsumeEmbeddedLib.csproj" />
<Project Path="ConsumeInBoxRuntimeInfo/ConsumeInBoxRuntimeInfo.csproj" />
<Project Path="ConsumeIncorrectVersions/ConsumeIncorrectVersions.csproj" />
Expand Down
40 changes: 40 additions & 0 deletions src/Polyfill/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if !NET11_0_OR_GREATER

namespace System.Runtime.CompilerServices;

using Diagnostics;
using Diagnostics.CodeAnalysis;

/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.isclosedtypeattribute?view=net-11.0
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;

/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}

#else
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsClosedTypeAttribute))]
#endif
32 changes: 32 additions & 0 deletions src/Split/net10.0/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
1 change: 1 addition & 0 deletions src/Split/net11.0/TypeForwardeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[assembly: TypeForwardedTo(typeof(System.Diagnostics.CodeAnalysis.FeatureGuardAttribute))]
[assembly: TypeForwardedTo(typeof(System.Diagnostics.CodeAnalysis.FeatureSwitchDefinitionAttribute))]
[assembly: TypeForwardedTo(typeof(System.Collections.Generic.IAlternateEqualityComparer<,>))]
[assembly: TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsClosedTypeAttribute))]
[assembly: TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsExternalInit))]
[assembly: TypeForwardedTo(typeof(System.Collections.Generic.KeyValuePair))]
[assembly: TypeForwardedTo(typeof(System.Threading.Lock))]
Expand Down
32 changes: 32 additions & 0 deletions src/Split/net461/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
32 changes: 32 additions & 0 deletions src/Split/net462/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
32 changes: 32 additions & 0 deletions src/Split/net47/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
32 changes: 32 additions & 0 deletions src/Split/net471/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
32 changes: 32 additions & 0 deletions src/Split/net472/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
32 changes: 32 additions & 0 deletions src/Split/net48/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
32 changes: 32 additions & 0 deletions src/Split/net481/IsClosedTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
#pragma warning disable
namespace System.Runtime.CompilerServices;
using Diagnostics;
using Diagnostics.CodeAnalysis;
/// <summary>
/// Reserved for use by a compiler for tracking metadata.
/// This attribute should not be used by developers in source code.
/// </summary>
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
#if PolyUseEmbeddedAttribute
[global::Microsoft.CodeAnalysis.EmbeddedAttribute]
#endif
#if PolyPublic
public
#endif
sealed class IsClosedTypeAttribute :
Attribute
{
Type[] derivedTypes = Type.EmptyTypes;
/// <summary>
/// Gets or sets the derived types of the closed type.
/// A <see langword="null"/> value is normalized to an empty array.
/// </summary>
public Type[] DerivedTypes
{
get => derivedTypes;
set => derivedTypes = value ?? Type.EmptyTypes;
}
}
Loading
Loading