Init(args)
Scripting Reference
Loading...
Searching...
No Matches
Sisus.NullExtensions Class Reference

Description

Helper class for checking whether the value of a variable that is of object, interface or generic type is null, destroyed or inactive.

By adding a using static directive it is possible to access the static members of the NullExtensions class without having to qualify the access with the type name, making it possible to perform safe and reliable null-checking conveniently by comparing objects against Null or NullOrInactive.

using Sisus.Init;
using static Sisus.NullExtensions;
public class EventListener : MonoBehaviour{IEvent}, IEventListener
{
private IEvent trigger;
protected override void Init(IEventBroadcaster trigger)
{
this.trigger = trigger;
}
private void OnEnable()
{
trigger.AddListener(this);
}
private void OnEvent()
{
Debug.Log($"{name} heard event {trigger}.");
}
private void OnDisable()
{
if(trigger != Null)
{
trigger.RemoveListener(this);
}
}
}
static readonly NullComparer Null
A value against which any object can be compared to determine whether it is null or an Object which h...
Definition NullExtensions.cs:95
Helper class for checking whether the value of a variable that is of object, interface or generic typ...
Definition NullExtensions.cs:57
@ OnEnable
The method is getting called from an OnEnable event function.
Definition Context.cs:106
Definition Any.cs:16
Definition Any.cs:16

Classes

class  NullComparer
 Represents a null reference or an Object that has been destroyed. More...
 
class  NullOrInactiveComparer
 Represents a null reference or an Object that has been destroyed or is inactive. More...
 

Static Public Member Functions

static void ThrowIfNull< TObject > (TObject reference, string exceptionMessage)
 Throws an ArgumentNullException if reference is null or a destroyed Object.
 
static void ThrowIfNull (Object reference, string exceptionMessage, Type type)
 Throws an ArgumentNullException if reference is null or a destroyed Object.
 
static void ThrowIfNull (object reference, string exceptionMessage, Type type)
 Throws an ArgumentNullException if reference is null or a destroyed Object.
 

Static Public Attributes

static readonly NullComparer Null = new NullComparer()
 A value against which any object can be compared to determine whether it is null or an Object which has been destroyed.
 
static readonly NullOrInactiveComparer NullOrInactive = new NullOrInactiveComparer()
 A value against which any object can be compared to determine whether it is null or an Object which is inactive or has been destroyed.