Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication7
  9. {
  10.     interface IClass<T>
  11.     {
  12.        
  13.     }
  14.  
  15.     class Class1<T> : IClass<T>
  16.     {
  17.        
  18.     }
  19.  
  20.     class Class2<T> : IClass<T>
  21.     {
  22.        
  23.     }
  24.  
  25.     class Class3 : IClass<int>
  26.     {
  27.        
  28.     }
  29.  
  30.     class Program
  31.     {
  32.         static void Main(string[] args)
  33.         {
  34.             // only prints Class3
  35.             foreach (var type in GetClosedGenericSubClasses<int>())
  36.             {
  37.                 Console.WriteLine(type.FullName);
  38.             }
  39.         }
  40.  
  41.         static IEnumerable<Type> GetClosedGenericSubClasses<U>()
  42.         {
  43.  
  44.             return Assembly.GetExecutingAssembly().GetTypes().Where(type => typeof(IClass<U>).IsAssignableFrom(type));
  45.             //return Assembly.GetExecutingAssembly().GetTypes().Where(type => type.IsSubclassOf(typeof(IClass<U>)));
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement