Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Threading.Tasks;
- namespace test_reflect
- {
- class Program
- {
- static async Task Main(string[] args)
- {
- List<IBase> commands = new List<IBase>();
- foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
- {
- if (typeof(IBase).IsAssignableFrom(type) && !type.IsAbstract)
- {
- commands.Add(Activator.CreateInstance(type) as IBase);
- }
- }
- }
- }
- public interface IBase { }
- public class SomeCommand : IBase {}
- public class OtherCommand : IBase {}
- public class AdditionalCommand : IBase {}
- }
Add Comment
Please, Sign In to add comment