Skip to content

API Proposal: Unsafe.IsNullRef(ref readonly) #73608

Closed
@hez2010

Description

@hez2010

Background and motivation

Currently we cannot test whether a ref readonly is null ref or not because Unsafe.IsNullRef() takes a ref parameter instead of ref readonly parameter.
Given that Unsafe.IsNullRef doesn’t need mutability, the signature should be changed from IsNullRef(ref) to IsNullRef(ref readonly).

API Proposal

namespace System.Runtime.CompilerServices;

public static class Unsafe
{
-    public bool IsNullRef(ref value);
+    public bool IsNullRef(ref readonly value); // or in value
}

API Usage

ref readonly int Foo() {}
ref readonly int x = ref Foo();
Unsafe.IsNullRef(in x);

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions