Debug.Log Extensions
Documentation (1.1.9)

◆ Guard() [2/2]

static bool Sisus.Debugging.Dev.Guard ( bool  condition,
int  channel,
Object  context = null 
)
static

If condition is false logs to the Console on the given channel an error message and returns true.

If condition is true returns false without logging anything.

This can be useful for checking that the arguments passed to a function are valid and if not returning early with an error.

An error is only logged the first time during a session that the condition evaluates to false to avoid flooding the log file.

An error will only be logged in builds if the DEBUG symbol is defined, like for example in development builds.

private void CopyComponent(Component component, GameObject to)
{
if(Debug.Guard(component != null && to != null))
{
return;
}
var copy = to.AddComponent(component.GetType());
var json = JsonUtility.ToJson(component);
JsonUtility.FromJsonOverwrite(json, copy);
}
static bool Guard(bool condition, Object context=null)
If condition is false logs to the Console an error message and returns true.
Definition: Debug.cs:4102
Extended version of the built-in Debug class with additional methods to ease debugging while developi...
Definition: Debug.cs:34
Parameters
conditionCondition you expect to be true.
channelThe channel to which the message belongs if logged.
contextObject to which the assertion applies.
Returns
true if condition was false; otherwise, false.