How to simulate List<T>.Any method via MethodInfo?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 23:03:56

问题


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.

来源:https://stackoverflow.com/questions/55586426/how-to-simulate-listt-any-method-via-methodinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!