How to add a component to all selected objects?

I didn’t found a build in function anywhere so I decided to write my own.

This is my script

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

class AddCollideres
{
    [MenuItem("Component/Plugins/Add colliders selected gameobjects")]
    static void Execute()
    {
        foreach (GameObject obj in Selection.activeGameObject) {
			Debug.Log(obj);
        }	
	}
	[MenuItem ("Component/Plugins/Add colliders to children", true)]
    static bool ValidateSelection () {
        return Selection.activeGameObject   != null;
    }
}

It isn’t finished yet because i’m stuck. How do read multiple selected gameobjects?

[Edit by Berenger, code formatting]

Try this :

static void Execute()
{
    foreach (GameObject obj in Selection.gameObjects) {
        obj.AddComponent( typeof(...) );
    }
}