get component type at runtime using generic GetComponent in C#

hello,
so I find myself using a lot of objects that have several children that either contain audio, particle systems, materials, etc. It often happens that I need to disable them for all of the transform children without destroying the object.

I’ve written recursive searches to disable the specific type of component that I need at that time, but how can I write a generic script that just takes any component as an argument and searches for it? This is what I’ve come up with so far, and it doesn’t work since Component itself cannot be enabled/disabled, but only the class types that inherit from it (e.g. rigidbody, light, etc). How can I rework this so that I can use a generic?

using UnityEngine;
using System.Collections;

public static class CheckComponent 
{
	public static T Check<T> (this Transform t) where T : Component
	{
	   	T component = t.GetComponent<T>();
	 
	   if(component == null)
	   {
			Debug.LogError("Search for component type " + typeof(T) + " yielded no results", t);
	   }
	 
	   return component;
	}
	
	public static void RecursiveDisable<T> (this Transform t) where T : Component
	{
		T component = t.GetComponent<T>();
		
		if(component == null)
		{
			Debug.LogError("Attempting to disable component type " + typeof(T) + ", but " + t + " has none");
		}
		else
		{
			//component.enabled = false; // not possible, only children that inherit from component can be enabled/disabled
		}
		if(t.childCount > 0)
		{
			foreach(Transform child in t)
				child.RecursiveDisable<T>();
		}
		else
		{
			//done
		}
		
	}
}

Components can’t be disabled, right. That’s why there is the type Behaviour which is derived from Component which introduces the “enabled” property. A lot components are derived from Behaviour including MonoBehaviour (so all your scripts included). However there are some other built-in components which bring their own enabled property, so they don’t share it via inheritance. Two important ones are the Collider and the Renderer base-class.

There are other components as well which can be enabled in some way (ParticleSystem, Rigidbody) but don’t have an enabled property. A more general approach is to simply disable the gameobject the component is attached to. This will disable the components as well.

See the inheritance tree for more insight.

edit
If you just care about the major components, you could do something like that:

if(component == null)
{
    //[...]
}
else
{
    if (component is Behaviour)
        (component as Behaviour).enabled = false;
    else if (component is Collider)
        (component as Collider).enabled = false;
    else if (component is Renderer)
        (component as Renderer).enabled = false;
}