Code/General/ComponentListExtensions.cs
using ExtendedBox.General.Exceptions;
using Sandbox;
using System;

namespace ExtendedBox.General;

public static class ComponentListExtensions
{
    public static Component? Get(this ComponentList components, Type type, bool includeDisabled = false) =>
        components.Get(type, includeDisabled ? FindMode.EverythingInSelf : FindMode.EnabledInSelf);


    public static T GetOrThrow<T>(this ComponentList components, bool includeDisabled = false) =>
        components.Get<T>(includeDisabled) ?? throw new ComponentNotFoundException<T>();

    public static T GetOrThrow<T>(this ComponentList components, FindMode findMode) =>
        components.Get<T>(findMode) ?? throw new ComponentNotFoundException<T>();

    public static Component GetOrThrow(this ComponentList components, Type type, bool includeDisabled = false) =>
        components.Get(type, includeDisabled) ?? throw new ComponentNotFoundException(type);

    public static Component GetOrThrow(this ComponentList components, Type type, FindMode findMode) =>
        components.Get(type, findMode) ?? throw new ComponentNotFoundException(type);

    public static Component GetOrThrow(this ComponentList components, Guid guid) =>
        components.Get(guid) ?? throw new ComponentNotFoundException(guid);
}