fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using System.Linq;
  5.  
  6. public class Test
  7. {
  8.  
  9. public void Delete<T>(T obj) where T : class {}
  10. public void Delete<T>(ICollection<T> obj) where T : class {}
  11.  
  12. public static MethodInfo GetMethod(Type type) {
  13. var res = type
  14. .GetRuntimeMethods()
  15. .Where(x => x.Name.Equals("Select"))
  16. .Select(m => new {Method = m, Parameters = m.GetParameters()})
  17. .FirstOrDefault(p =>
  18. p.Parameters.Length == 1
  19. && p.Parameters[0].ParameterType.IsGenericType
  20. && p.Parameters[0].ParameterType.GetGenericTypeDefinition() == typeof(ICollection<>)
  21. );
  22. return res != null ? res.Method : null;
  23. }
  24.  
  25. public static void Main()
  26. {
  27. Console.WriteLine(GetMethod(typeof(Test)));
  28. }
  29. }
Success #stdin #stdout 0.05s 27416KB
stdin
Standard input is empty
stdout