Guest User

Untitled

a guest
Mar 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Threading.Tasks;
  6.  
  7. namespace test_reflect
  8. {
  9. class Program
  10. {
  11. static async Task Main(string[] args)
  12. {
  13. List<IBase> commands = new List<IBase>();
  14.  
  15. foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
  16. {
  17. if (typeof(IBase).IsAssignableFrom(type) && !type.IsAbstract)
  18. {
  19. commands.Add(Activator.CreateInstance(type) as IBase);
  20. }
  21. }
  22. }
  23. }
  24.  
  25. public interface IBase { }
  26.  
  27. public class SomeCommand : IBase {}
  28. public class OtherCommand : IBase {}
  29. public class AdditionalCommand : IBase {}
  30. }
Add Comment
Please, Sign In to add comment