src/Compilers/CSharp/Test/Semantic/Semantics/NativeIntegerTests.cs
/// <summary>
/// Static members Zero, Size, Add(), Subtract() are explicitly excluded from nint and nuint.
/// Other static members are implicitly included on nint and nuint.
/// </summary>
Static members Zero, Size, Add(), Subtract() are explicitly excluded from nint and nuint.
Other static members are implicitly included on nint and nuint.
Static members Zero Size Add () Subtract () are explicitly excluded from nint and nuint . Other static members are implicitly included on nint and nuint .
[Theory]
        [InlineData(false)]
        [InlineData(true)]
        public void StaticMembers(bool useCompilationReference)
        {
            var sourceA =
@"namespace System
{
    public class Object { }
    public class String { }
    public abstract class ValueType { }
    public struct Void { }
    public struct Boolean { }
    public struct Int32 { }
    public struct IntPtr
    {
        public static readonly IntPtr Zero;
        public static int Size => 0;
        public static IntPtr MaxValue => default;
        public static IntPtr MinValue => default;
        public static IntPtr Add(IntPtr ptr, int offset) => default;
        public static IntPtr Subtract(IntPtr ptr, int offset) => default;
        public static IntPtr Parse(string s) => default;
        public static bool TryParse(string s, out IntPtr value)
        {
            value = default;
            return false;
        }
    }
    public struct UIntPtr
    {
        public static readonly UIntPtr Zero;
        public static int Size => 0;
        public static UIntPtr MaxValue => default;
        public static UIntPtr MinValue => default;
        public static UIntPtr Add(UIntPtr ptr, int offset) => default;
        public static UIntPtr Subtract(UIntPtr ptr, int offset) => default;
        public static UIntPtr Parse(string s) => default;
        public static bool TryParse(string s, out UIntPtr value)
        {
            value = default;
            return false;
        }
    }
}";
            var comp = CreateEmptyCompilation(sourceA);
            comp.VerifyDiagnostics();
            var refA = AsReference(comp, useCompilationReference);
            var sourceB =
@"class Program
{
    static nint F1()
    {
        _ = nint.Zero;
        _ = nint.Size;
        var x1 = nint.MaxValue;
        var x2 = nint.MinValue;
        _ = nint.Add(x1, 2);
        _ = nint.Subtract(x1, 3);
        var x3 = nint.Parse(null);
        _ = nint.TryParse(null, out var x4);
        return 0;
    }
    static nuint F2()
    {
        _ = nuint.Zero;
        _ = nuint.Size;
        var y1 = nuint.MaxValue;
        var y2 = nuint.MinValue;
        _ = nuint.Add(y1, 2);
        _ = nuint.Subtract(y1, 3);
        var y3 = nuint.Parse(null);
        _ = nuint.TryParse(null, out var y4);
        return 0;
    }
}";
            comp = CreateEmptyCompilation(sourceB, references: new[] { refA }, parseOptions: TestOptions.RegularPreview);
            comp.VerifyDiagnostics(
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Zero").WithArguments("nint", "Zero").WithLocation(5, 18),
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Size").WithArguments("nint", "Size").WithLocation(6, 18),
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Add").WithArguments("nint", "Add").WithLocation(9, 18),
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Subtract").WithArguments("nint", "Subtract").WithLocation(10, 18),
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Zero").WithArguments("nuint", "Zero").WithLocation(17, 19),
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Size").WithArguments("nuint", "Size").WithLocation(18, 19),
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Add").WithArguments("nuint", "Add").WithLocation(21, 19),
                Diagnostic(ErrorCode.ERR_NoSuchMember, "Subtract").WithArguments("nuint", "Subtract").WithLocation(22, 19));
            verifyType((NamedTypeSymbol)comp.GetMember<MethodSymbol>("Program.F1").ReturnType, signed: true);
            verifyType((NamedTypeSymbol)comp.GetMember<MethodSymbol>("Program.F2").ReturnType, signed: false);
            var tree = comp.SyntaxTrees[0];
            var model = comp.GetSemanticModel(tree);
            var actualLocals = tree.GetRoot().DescendantNodes().OfType<VariableDeclaratorSyntax>().Select(d => model.GetDeclaredSymbol(d).ToTestDisplayString());
            var expectedLocals = new[]
            {
                "nint x1",
                "nint x2",
                "nint x3",
                "nuint y1",
                "nuint y2",
                "nuint y3",
            };
            AssertEx.Equal(expectedLocals, actualLocals);
            static void verifyType(NamedTypeSymbol type, bool signed)
            {
                Assert.True(type.IsNativeIntegerType);
                VerifyType(type, signed: signed, isNativeInt: true);
                VerifyType(type.GetPublicSymbol(), signed: signed, isNativeInt: true);
                var members = type.GetMembers().Sort(SymbolComparison);
                var actualMembers = members.SelectAsArray(m => m.ToTestDisplayString());
                var expectedMembers = new[]
                {
                    $"System.Boolean {type}.TryParse(System.String s, out {type} value)",
                    $"{type} {type}.MaxValue {{ get; }}",
                    $"{type} {type}.MaxValue.get",
                    $"{type} {type}.MinValue {{ get; }}",
                    $"{type} {type}.MinValue.get",
                    $"{type} {type}.Parse(System.String s)",
                    $"{type}..ctor()",
                };
                AssertEx.Equal(expectedMembers, actualMembers);
                var property = (PropertySymbol)members.Single(m => m.Name == "MaxValue");
                var getMethod = (MethodSymbol)members.Single(m => m.Name == "get_MaxValue");
                Assert.Same(getMethod, property.GetMethod);
                Assert.Null(property.SetMethod);
                var underlyingType = type.NativeIntegerUnderlyingType;
                VerifyMembers(underlyingType, type, signed);
                VerifyMembers(underlyingType.GetPublicSymbol(), type.GetPublicSymbol(), signed);
            }
        }
[ Theory ] [ InlineData ( false ) ] [ InlineData ( true ) ] public void StaticMembers ( bool useCompilationReference ) { var sourceA = @"namespace System
{
    public class Object { }
    public class String { }
    public abstract class ValueType { }
    public struct Void { }
    public struct Boolean { }
    public struct Int32 { }
    public struct IntPtr
    {
        public static readonly IntPtr Zero;
        public static int Size => 0;
        public static IntPtr MaxValue => default;
        public static IntPtr MinValue => default;
        public static IntPtr Add(IntPtr ptr, int offset) => default;
        public static IntPtr Subtract(IntPtr ptr, int offset) => default;
        public static IntPtr Parse(string s) => default;
        public static bool TryParse(string s, out IntPtr value)
        {
            value = default;
            return false;
        }
    }
    public struct UIntPtr
    {
        public static readonly UIntPtr Zero;
        public static int Size => 0;
        public static UIntPtr MaxValue => default;
        public static UIntPtr MinValue => default;
        public static UIntPtr Add(UIntPtr ptr, int offset) => default;
        public static UIntPtr Subtract(UIntPtr ptr, int offset) => default;
        public static UIntPtr Parse(string s) => default;
        public static bool TryParse(string s, out UIntPtr value)
        {
            value = default;
            return false;
        }
    }
}" ; var comp = CreateEmptyCompilation ( sourceA ) ; comp . VerifyDiagnostics ( ) ; var refA = AsReference ( comp , useCompilationReference ) ; var sourceB = @"class Program
{
    static nint F1()
    {
        _ = nint.Zero;
        _ = nint.Size;
        var x1 = nint.MaxValue;
        var x2 = nint.MinValue;
        _ = nint.Add(x1, 2);
        _ = nint.Subtract(x1, 3);
        var x3 = nint.Parse(null);
        _ = nint.TryParse(null, out var x4);
        return 0;
    }
    static nuint F2()
    {
        _ = nuint.Zero;
        _ = nuint.Size;
        var y1 = nuint.MaxValue;
        var y2 = nuint.MinValue;
        _ = nuint.Add(y1, 2);
        _ = nuint.Subtract(y1, 3);
        var y3 = nuint.Parse(null);
        _ = nuint.TryParse(null, out var y4);
        return 0;
    }
}" ; comp = CreateEmptyCompilation ( sourceB , references : new [ ] { refA } , parseOptions : TestOptions . RegularPreview ) ; comp . VerifyDiagnostics ( Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 5 , 18 ) , Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 6 , 18 ) , Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 9 , 18 ) , Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 10 , 18 ) , Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 17 , 19 ) , Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 18 , 19 ) , Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 21 , 19 ) , Diagnostic ( ErrorCode . ERR_NoSuchMember , " " ) . WithArguments ( " " , " " ) . WithLocation ( 22 , 19 ) ) ; verifyType ( ( NamedTypeSymbol ) comp . GetMember < MethodSymbol > ( " " ) . ReturnType , signed : true ) ; verifyType ( ( NamedTypeSymbol ) comp . GetMember < MethodSymbol > ( " " ) . ReturnType , signed : false ) ; var tree = comp . SyntaxTrees [ 0 ] ; var model = comp . GetSemanticModel ( tree ) ; var actualLocals = tree . GetRoot ( ) . DescendantNodes ( ) . OfType < VariableDeclaratorSyntax > ( ) . Select ( d => model . GetDeclaredSymbol ( d ) . ToTestDisplayString ( ) ) ; var expectedLocals = new [ ] { " " , " " , " " , " " , " " , " " , } ; AssertEx . Equal ( expectedLocals , actualLocals ) ; static void verifyType ( NamedTypeSymbol type , bool signed ) { Assert . True ( type . IsNativeIntegerType ) ; VerifyType ( type , signed : signed , isNativeInt : true ) ; VerifyType ( type . GetPublicSymbol ( ) , signed : signed , isNativeInt : true ) ; var members = type . GetMembers ( ) . Sort ( SymbolComparison ) ; var actualMembers = members . SelectAsArray ( m => m . ToTestDisplayString ( ) ) ; var expectedMembers = new [ ] { $" System.Boolean  { type } .TryParse(System.String s, out  { type }  value) " , $" { type } { type } .MaxValue  {{  get; }} " , $" { type } { type } .MaxValue.get " , $" { type } { type } .MinValue  {{  get; }} " , $" { type } { type } .MinValue.get " , $" { type } { type } .Parse(System.String s) " , $" { type } ..ctor() " , } ; AssertEx . Equal ( expectedMembers , actualMembers ) ; var property = ( PropertySymbol ) members . Single ( m => m . Name == " " ) ; var getMethod = ( MethodSymbol ) members . Single ( m => m . Name == " " ) ; Assert . Same ( getMethod , property . GetMethod ) ; Assert . Null ( property . SetMethod ) ; var underlyingType = type . NativeIntegerUnderlyingType ; VerifyMembers ( underlyingType , type , signed ) ; VerifyMembers ( underlyingType . GetPublicSymbol ( ) , type . GetPublicSymbol ( ) , signed ) ; } }
Static members Zero, Size, Add(), Subtract() are explicitly excluded from nint and nuint.
Static members Zero Size Add () Subtract () are explicitly excluded from nint and nuint .
// (5,18): error CS0117: 'nint' does not contain a definition for 'Zero' //         _ = nint.Zero; // (6,18): error CS0117: 'nint' does not contain a definition for 'Size' //         _ = nint.Size; // (9,18): error CS0117: 'nint' does not contain a definition for 'Add' //         _ = nint.Add(x1, x2); // (10,18): error CS0117: 'nint' does not contain a definition for 'Subtract' //         _ = nint.Subtract(x1, x2); // (17,19): error CS0117: 'nuint' does not contain a definition for 'Zero' //         _ = nuint.Zero; // (18,19): error CS0117: 'nuint' does not contain a definition for 'Size' //         _ = nuint.Size; // (21,19): error CS0117: 'nuint' does not contain a definition for 'Add' //         _ = nuint.Add(y1, y2); // (22,19): error CS0117: 'nuint' does not contain a definition for 'Subtract' //         _ = nuint.Subtract(y1, y2);
useCompilationReference
bool