Class CanBeNullAttribute
- Namespace
- Stride.Core.Annotations
- Assembly
- Stride.Core.dll
Indicates that the value of the marked element could be null
sometimes, so the check for null
is necessary before its usage.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event|AttributeTargets.Interface|AttributeTargets.Parameter|AttributeTargets.Delegate|AttributeTargets.GenericParameter)]
public sealed class CanBeNullAttribute : Attribute
- Inheritance
-
CanBeNullAttribute
- Inherited Members
Examples
[CanBeNull] object Test() => null;
void UseTest() {
var p = Test();
var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
}