public ICollection <int> Sort (ICollection <int> collection, string algorithm) { //var allTypes = Assembly // .GetExecutingAssembly() // .GetTypes() // .ToList(); // all classes in the assembly var sorterType = Assembly .GetExecutingAssembly() .GetTypes() .Where(t => typeof(ISortingStrategyPattern).IsAssignableFrom(t) && t.IsClass) .FirstOrDefault(t => t.Name.ToLower().Contains(algorithm)); ISortingStrategyPattern pattern = (ISortingStrategyPattern)Activator.CreateInstance(sorterType); return(pattern.Sort(collection)); }