From ea8cad6679ca519dde6791910f44358b6bd3afc6 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Mon, 22 Jan 2024 18:14:37 -0800 Subject: [PATCH 1/2] Add CollectionBuilderAttribute to System.Collections.Immutable CollectionBuilderAttribute is another attribute that's used to light-up compiler API. This attribute is filtered by GenAPI. Add it back manually to support Collection expressions with immutable collections. https://github.com/dotnet/sdk/issues/33693 --- src/referencePackages/Directory.Build.targets | 2 +- .../System.Collections.Immutable.8.0.0.csproj | 5 ++ .../System.Collections.Immutable.Manual.cs | 53 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs diff --git a/src/referencePackages/Directory.Build.targets b/src/referencePackages/Directory.Build.targets index 94669bd124..2a66234432 100644 --- a/src/referencePackages/Directory.Build.targets +++ b/src/referencePackages/Directory.Build.targets @@ -112,7 +112,7 @@ AfterTargets="CopyFilesToOutputDirectory"> - + System.Collections.Immutable + + + + + diff --git a/src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs b/src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs new file mode 100644 index 0000000000..2b6ef0e4ab --- /dev/null +++ b/src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs @@ -0,0 +1,53 @@ + +namespace System.Collections.Immutable +{ + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableList), "Create")] + public partial interface IImmutableList + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableQueue), "Create")] + public partial interface IImmutableQueue + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableHashSet), "Create")] + public partial interface IImmutableSet + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableStack), "Create")] + public partial interface IImmutableStack + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableArray), "Create")] + public readonly partial struct ImmutableArray + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableHashSet), "Create")] + public sealed partial class ImmutableHashSet + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableList), "Create")] + public sealed partial class ImmutableList + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableQueue), "Create")] + public sealed partial class ImmutableQueue + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableSortedSet), "Create")] + public sealed partial class ImmutableSortedSet + {} + + [Runtime.CompilerServices.CollectionBuilder(typeof(ImmutableStack), "Create")] + public sealed partial class ImmutableStack + {} +} + +namespace System.Runtime.CompilerServices +{ + internal sealed class CollectionBuilderAttribute(Type builderType, string methodName) : Attribute + { + public Type BuilderType { get; } = builderType; + + public string MethodName { get; } = methodName; + } +} \ No newline at end of file From 38066edfaad4a6fd9ebe9e5ff0b272af0a2ff1b6 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Tue, 23 Jan 2024 06:33:00 -0800 Subject: [PATCH 2/2] Add header and link to issue --- .../8.0.0/System.Collections.Immutable.Manual.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs b/src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs index 2b6ef0e4ab..d5a436a142 100644 --- a/src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs +++ b/src/referencePackages/src/system.collections.immutable/8.0.0/System.Collections.Immutable.Manual.cs @@ -1,3 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// ------------------------------------------------------------------------------ +// Changes to this file must follow the http://aka.ms/api-review process. +// ------------------------------------------------------------------------------ + +// See https://github.com/dotnet/sdk/issues/33693 for why this is necessary. namespace System.Collections.Immutable {