How to simulate List.Any method via MethodInfo?

2019-07-26 06:44发布

I try to simulate List<T>.Any method via MethodInfo. First I define a class:

class Test
{
    int _value;
    public int Value { get; set; }

    public Test(int v)
    {
        _value = v;
    }
}

..and then I create a List<Test>

List<C> list = new List<C>();
for (int i = 0; i < 10; i++)
{
    list.Add(new C(i));
}

My aim to call list.Any(c=>c.Value>3) via MethodInfo, now I met the problem about how to locate the real method. I can find Any() method in System.Linq.Enumerable and System.Linq.Queryable.

When I check the definition about List<>, I think I should use the method in System.Linq.Enumerable, because it implements IEnumerable, is it right?

Now I have a new question if a class implements both IEnumerable and IQueryable, which MethodInfo should I use, such as Any(), Sum(), and so on.

0条回答
登录 后发表回答