vendredi 3 mars 2017

How to convert "where" method into reflection in Linq Expresion?

I want to convert where method of linq expression in reflection.

exp1 = p2 => p2.s[new int[] { 14, 5 }].Select((item, index) => new { item, index }).Where(x=>x.index > 2).Select(x => x.index).ToList();

I already converted select method in reflection like below:

var enumerableSelectIndexTSourceTResult = (from x in typeof(Enumerable).GetMethods()
                                                       where x.Name == "Select" && x.IsGenericMethod
                                                       let args = x.GetGenericArguments()
                                                       where args.Length == 2
                                                       let pars = x.GetParameters()
                                                       where pars.Length == 2 &&
                                                           pars[0].ParameterType == typeof(IEnumerable<>).MakeGenericType(args[0]) &&
                                                           pars[1].ParameterType == typeof(Func<,,>).MakeGenericType(args[0], typeof(int), args[1])
                                                   select x).Single();

In this way I want to convert where method in reflection.





Aucun commentaire:

Enregistrer un commentaire