Advertisement
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.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication7
- {
- interface IClass<T>
- {
- }
- class Class1<T> : IClass<T>
- {
- }
- class Class2<T> : IClass<T>
- {
- }
- class Class3 : IClass<int>
- {
- }
- class Program
- {
- static void Main(string[] args)
- {
- // only prints Class3
- foreach (var type in GetClosedGenericSubClasses<int>())
- {
- Console.WriteLine(type.FullName);
- }
- }
- static IEnumerable<Type> GetClosedGenericSubClasses<U>()
- {
- return Assembly.GetExecutingAssembly().GetTypes().Where(type => typeof(IClass<U>).IsAssignableFrom(type));
- //return Assembly.GetExecutingAssembly().GetTypes().Where(type => type.IsSubclassOf(typeof(IClass<U>)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement