Class NotNullRefAttribute
Marks a ref, in, ref readonly or out parameter of a method that
returns only if the reference that it is given refers to something: given a null reference, as Unsafe.NullRef makes one, the method
throws.
Inherited Members
Namespace: Singulink.CodeAnalysis
Assembly: Singulink.CodeAnalysis.dll
Syntax
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
public sealed class NotNullRefAttribute : Attribute
Remarks
A read or a write through a null reference fails, so 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 a method with this attribute that returns, the reference that was passed to the marked
parameter is known to refer to something. ThrowIfNullRef<T>(ref readonly T, string?) and ThrowIfNullRefArgument<T>(ref readonly T, string?)
are such methods.
The attribute counts where a call names the code that runs: on a method that is not virtual, abstract or an override, static or not, an extension method included, and on a local function. Anywhere else it gets a warning.
The analyzer does not check the body of the method. The attribute is a statement of its author, and every use of it in a project gets one warning, to be suppressed there when the method has been verified and tested.
The analyzer recognizes the attribute by its full name, Singulink.CodeAnalysis.NotNullRefAttribute, in any assembly, public or
internal.