fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5.  
  6. public class MyClass<T>
  7. {
  8. public T MainModel { get; set; }
  9.  
  10. public Type GetTheType()
  11. {
  12. return typeof(T).GetInterfaces().Where(i => i.IsGenericType)
  13. .Single(i => i.GetGenericTypeDefinition() == typeof(IEnumerable<>))
  14. .GetGenericArguments().First();
  15. }
  16. }
  17.  
  18. public class Test
  19. {
  20. public static void Main()
  21. {
  22. var mainInstance = new MyClass<List<string>>();
  23. Console.Out.WriteLine(mainInstance.GetTheType().FullName);
  24. }
  25. }
Success #stdin #stdout 0.04s 37064KB
stdin
Standard input is empty
stdout
System.String