Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add collection literal support for immutable collections (#88470)
* Add collection literal support for immutable collections Add the CollectionBuilderAttribute and use it on the supported immutable collections * Address feedback
- Loading branch information
1 parent
58bca2c
commit ec025ad
Showing
13 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.../System.Private.CoreLib/src/System/Runtime/CompilerServices/CollectionBuilderAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)] | ||
#if SYSTEM_PRIVATE_CORELIB | ||
public | ||
#else | ||
internal | ||
#endif | ||
sealed class CollectionBuilderAttribute : Attribute | ||
{ | ||
/// <summary>Initialize the attribute to refer to the <paramref name="methodName"/> method on the <paramref name="builderType"/> type.</summary> | ||
/// <param name="builderType">The type of the builder to use to construct the collection.</param> | ||
/// <param name="methodName">The name of the method on the builder to use to construct the collection.</param> | ||
/// <remarks> | ||
/// <paramref name="methodName"/> must refer to a static method that accepts a single parameter of | ||
/// type <see cref="ReadOnlySpan{T}"/> and returns an instance of the collection being built containing | ||
/// a copy of the data from that span. In future releases of .NET, additional patterns may be supported. | ||
/// </remarks> | ||
public CollectionBuilderAttribute(Type builderType, string methodName) | ||
{ | ||
BuilderType = builderType; | ||
MethodName = methodName; | ||
} | ||
|
||
/// <summary>Gets the type of the builder to use to construct the collection.</summary> | ||
public Type BuilderType { get; } | ||
|
||
/// <summary>Gets the name of the method on the builder to use to construct the collection.</summary> | ||
/// <remarks>This should match the metadata name of the target method. For example, this might be ".ctor" if targeting the type's constructor.</remarks> | ||
public string MethodName { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters