using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var t1 = new Type1(); var t2 = new Type2(); var t3 = new Type3(); var handlers = new Handlers(); HandlersStorage.AddHandler(handlers.HaldlerOfType1); HandlersStorage.AddHandler(handlers.HaldlerOfType2); HandlersStorage.AddHandler((object o) => { Console.WriteLine("Haldler of Type3 is lambda"); }); var a1 = HandlersStorage.GetHandler(t1.GetType()); a1(t1); var a2 = HandlersStorage.GetHandler(t2.GetType()); a2(t2); var a3 = HandlersStorage.GetHandler(t3.GetType()); a3(t3); Console.ReadKey(); } } public static class HandlersStorage { private static Dictionary> _handlers = new Dictionary>(); public static void AddHandler(Action action) { _handlers.Add(typeof(T),action); } public static Action GetHandler(Type type) { return _handlers[type]; } } public class Handlers { public void HaldlerOfType1(object o) { Console.WriteLine("HaldlerOfType1"); } public void HaldlerOfType2(object o) { Console.WriteLine("HaldlerOfType2"); } } class Type1 { } class Type2 { } class Type3 { } }