Code Analysis Code Analysis
Code Analysis Code Analysis
DocFX + Singulink = ♥

Search Results for

    Method ThrowIfNullRef

    ThrowIfNullRef<T>(ref readonly T, string?)

    Throws a NullReferenceException if a reference is a null reference, as NullRef<T>() makes one, and does nothing else.

    Declaration
    public static void ThrowIfNullRef<T>(ref readonly T reference, string? expression = null) where T : allows ref struct
    Parameters
    Type Name Description
    T reference

    The reference to check.

    string expression

    The expression that gives the reference, which the compiler fills in.

    Type Parameters
    Name Description
    T

    The type of what the reference refers to.

    Remarks

    A read or a write through a null reference fails with a NullReferenceException, which is why the analyzer counts a read or a write through a reference as able to throw where it asks what can: between the read and the assignment of a [MovedFrom] parameter, and after a value was committed at the end of a try block. After a call of this method the reference is known to refer to something.

    Use this one for this in a struct (NonCopyable.ThrowIfNullRef(in this)), for a ref local, and wherever a null reference is not the fault of an argument: the method then fails as it would have failed at its first use of the reference, only earlier. For a parameter of a public method, ThrowIfNullRefArgument<T>(ref readonly T, string?) names the argument.

    Exceptions
    Type Condition
    NullReferenceException

    reference is a null reference.

    © Singulink. All rights reserved.