Place onions in a 12- x 8- x 2- inch baking dish, and set aside.
Melt butter in a heavy saucepan over low heat; add flour, stirring until smooth. Cook 1 minute, stirring constantly. Gradually add half-and-half; cook over medium heat, stirring constantly, until thickened and bubbly. Stir in sherry, mushrooms, pimiento, salt, and pepper; pour sauce over onions.
Bake, uncovered, at 350° for 25 minutes. Sprinkle cheese over top of sauce; bake an additional 5 minutes or until cheese melts.