Skip to content

[API Proposal]: Add RuntimeFeature field to identify support for numeric IntPtr type #67966

@jcouv

Description

@jcouv

Background and motivation

As part of the statics in interfaces and numerics work, the IntPtr and UIntPtr types are going to be expanded and become numeric types.
This API request is to help Roslyn recognize platforms where it should treat nint/nuint as aliases for IntPtr/UIntPtr (tracking feature).

API Proposal

namespace System.Runtime.CompilerServices
{
    public static partial class RuntimeFeature
    {
+        /// <summary>
+        /// The presence of this field indicates a runtime where `System.IntPtr`/`System.UIntPtr` are numeric types.
+        /// </summary>
+        public const string NumericIntPtr = nameof(NumericIntPtr);
    }
}

API Usage

Used by Roslyn to detect if a runtime supports numeric IntPtr/UIntPtr types.

Alternative Designs

A conceivable alternative would be to look at some API markers on the IntPtr type (for example, does it implement a given numeric interface).
But a runtime feature flag is the preferred/typical way to indicate a feature to Roslyn.

In terms of names, some other options are UnifiedIntPtr or PrimitiveIntPtr.

Risks

None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions