Background and Motivation
Allow annotating references to System.IntPtr and System.UIntPtr as native integers in metadata.
See spec.
Proposed API
namespace System.Runtime.CompilerServices
{
[AttributeUsage(
AttributeTargets.Class |
AttributeTargets.Event |
AttributeTargets.Field |
AttributeTargets.GenericParameter |
AttributeTargets.Parameter |
AttributeTargets.Property |
AttributeTargets.ReturnValue,
AllowMultiple = false,
Inherited = false)]
public sealed class NativeIntegerAttribute : Attribute
{
public NativeIntegerAttribute()
{
TransformFlags = new[] { true };
}
public NativeIntegerAttribute(bool[] flags)
{
TransformFlags = flags;
}
public IList<bool> TransformFlags { get; }
}
}
Used by the C# compiler to represent type references to nint and nuint in metadata.
The C# compiler reserves the attribute for compiler use only.
If the attribute is not available in the compilation, the C# compiler will emit an internal attribute type with the same shape.
Usage Examples
Consider the following signature in C#:
static nint Sum(nint[] array)
{
}
In metadata:
[NativeInteger]
static System.IntPtr Sum(
[NativeInteger(new[] { false, true })] System.IntPtr[] array)
{
}
Background and Motivation
Allow annotating references to
System.IntPtrandSystem.UIntPtras native integers in metadata.See spec.
Proposed API
Used by the C# compiler to represent type references to
nintandnuintin metadata.The C# compiler reserves the attribute for compiler use only.
If the attribute is not available in the compilation, the C# compiler will emit an
internalattribute type with the same shape.Usage Examples
Consider the following signature in C#:
In metadata: