-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Closed
Copy link
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Reflection.Metadata
Milestone
Description
Background and motivation
The design for ByRefLike Generic constraints requires some new API surface area. Specifically the need to represent the new metadata values and a new feature flag to indicate support for the compiler.
API Proposal
Metadata enum values:
namespace System.Reflection
{
[Flags]
public enum GenericParameterAttributes
{
+ [Obsolete("No longer represents all special constraints")]
SpecialConstraintMask = 0x001C,
+ AcceptByRefLike = 0x0020,
}
}Feature flag.
namespace System.Runtime.CompilerServices
{
public static partial class RuntimeFeature
{
+ /// <summary>
+ /// Represents a runtime feature where byref-like types can be used in Generic parameters.
+ /// </summary>
+ public const string GenericsAcceptByRefLike = nameof(GenericsAcceptByRefLike);
}
}API Usage
Usage is similar to the official documentation for any of the existing GenericParameterAttributes enumeration values.
Alternative Designs
The following would represent a binary breaking change.
namespace System.Reflection
{
[Flags]
public enum GenericParameterAttributes
{
- SpecialConstraintMask = 0x001C,
+ SpecialConstraintMask = 0x003C,
+ AcceptByRefLike = 0x0020,
}
}Risks
Updating the enumeration value is troublesome since it contains a value that is a mask—an established anti-pattern. The "safest" way to handle this is the initial proposal but that does introduce confusion about new scenarios. It might be prudent to create a new API for accessing the specific constraints from the variance values.
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Reflection.Metadata