fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public abstract class AbstractValidator<T> {
  5. }
  6.  
  7. public class CreateTripValidator : AbstractValidator<int>
  8. {}
  9. public class CancelTripValidator : AbstractValidator<string>
  10. {}
  11.  
  12. public class Test
  13. {
  14. public static void Main()
  15. {
  16. var validatorType = typeof(AbstractValidator<>);
  17. Console.WriteLine(string.Join(",", validatorType.Assembly
  18. .GetTypes()
  19. .Where(t => IsSubclassOfRawGeneric(validatorType, t))
  20. .Select(t => t.Name)
  21. .ToArray()));
  22. }
  23.  
  24. private static bool IsSubclassOfRawGeneric(Type baseType, Type derivedType) {
  25. while (derivedType != null && derivedType != typeof(object)) {
  26. var currentType = derivedType.IsGenericType ? derivedType.GetGenericTypeDefinition() : derivedType;
  27. if (baseType == currentType) {
  28. return true;
  29. }
  30.  
  31. derivedType = derivedType.BaseType;
  32. }
  33. return false;
  34. }
  35.  
  36. }
Success #stdin #stdout 0.03s 33872KB
stdin
Standard input is empty
stdout
AbstractValidator`1,CreateTripValidator,CancelTripValidator