Debug.Log Extensions
Documentation (1.1.9)

◆ Guard< TException >()

static void Sisus.Debugging.Critical.Guard< TException > ( bool  condition,
params object[]  exceptionArguments 
)
static

Throws an exception of type TException if condition is not true.

This can be useful for checking that the arguments passed to a function are valid and if not aborting.

Note that an exception will be thrown every time that this method is called and condition evaluates to false. This is in contrast to some of the other Guard methods that only log an error once per session.

void CopyComponent(Component component, GameObject to)
{
Critical.Guard<ArgumentNullException>(component != null, nameof(component)));
Critical.Guard<ArgumentNullException>(to != null, nameof(to));
var copy = to.AddComponent(component.GetType());
var json = JsonUtility.ToJson(component);
JsonUtility.FromJsonOverwrite(json, copy);
}
Parameters
conditionCondition you expect to be true.
exceptionArgumentsOptional arguments to pass to the TException constructor when an exception is thrown.

Most exception constructors accept a string argument specifying the message to be logged to the Console. For ArgumentNullException on the other hand a single string argument specifies the name of the parameter that was null.

Type Constraints
TException :Exception 
TException :new()