Code/General/Exceptions/ComponentNotFoundException.cs
using Sandbox;
using System;
namespace ExtendedBox.General.Exceptions;
public class ComponentNotFoundException : Exception
{
public readonly GameObject? GameObject;
public readonly Type? Type;
public readonly Guid? Guid;
public ComponentNotFoundException(GameObject? gameObject, Type? type, Guid? guid) : base($"Component ({(type is null ? string.Empty : type.FullName)}){(guid.HasValue ? $" (with id ({guid}))" : string.Empty)} not found{(gameObject is null ? string.Empty : $" on {gameObject}")}.")
{
GameObject = gameObject;
Type = type;
Guid = guid;
}
public ComponentNotFoundException(GameObject gameObject, Type type) : this(gameObject, type, null)
{
}
public ComponentNotFoundException(GameObject gameObject, Guid guid) : this(gameObject, null, guid)
{
}
public ComponentNotFoundException(Type type, Guid guid) : this(null, type, guid)
{
}
public ComponentNotFoundException(Type type) : this(null, type, null)
{
}
public ComponentNotFoundException(Guid guid) : this(null, null, guid)
{
}
}
public class ComponentNotFoundException<T> : ComponentNotFoundException
{
public ComponentNotFoundException() : this(null, null)
{
}
public ComponentNotFoundException(GameObject? gameObject, Guid? guid) : base(gameObject, typeof(T), guid)
{
}
public ComponentNotFoundException(GameObject gameObject) : this(gameObject, null)
{
}
public ComponentNotFoundException(Guid guid) : this(null, guid)
{
}
}