0

Below is code fragments

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace DetailTest
{
class Program
{
    static void Main(string[] args)
    {
        A a = new A();
        PropertyInfo pi = a.GetType().GetProperty("cs");
        MemberInfo[] mis = pi.PropertyType.GetMembers();
        MemberInfo[] mis2 = mis.Where(d => d.Name.StartsWith("A")).ToArray();
        foreach (MemberInfo mi in mis2)
        {
            Console.WriteLine(mi);
        }
    }
}

class A
{
    B _b = new B();
    public B b { get{return _b;}}
    public List<C> cs{get;set;}
}
}

I just want to get Any method, but I got nothing. Why? I mean how to get Any method of List type?

ps: I really reference System.Linq

user2155362
  • 1,657
  • 5
  • 18
  • 30
  • 1
    [`Any` is a LINQ extension method](https://github.com/dotnet/corefx/blob/master/src/System.Linq/src/System/Linq/AnyAll.cs#L11-L45), if you remove `using System.Linq` you will see it's no longer available when you type `cs.` – ProgrammingLlama Apr 08 '19 at 02:53
  • Possible duplicate of [How to call a generic extension method with reflection?](https://stackoverflow.com/questions/15927028/how-to-call-a-generic-extension-method-with-reflection) – ProgrammingLlama Apr 08 '19 at 02:58
  • 1
    [Another duplicate](https://stackoverflow.com/questions/1452261/how-do-i-invoke-an-extension-method-using-reflection) – ProgrammingLlama Apr 08 '19 at 02:59
  • If you don't understand what extension methods are, you can check out the docs [here](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods). – ProgrammingLlama Apr 08 '19 at 03:00
  • What is the actual question here? – TheGeneral Apr 08 '19 at 04:00
  • Possible duplicate of [How do I invoke an extension method using reflection?](https://stackoverflow.com/questions/1452261/how-do-i-invoke-an-extension-method-using-reflection) – grek40 Apr 08 '19 at 05:29
  • As John said, the Any method is not a method of the List type. Rather, it is an extension method that work on any type that implements `IEnumerable`. As suggested in other comments, read more about extension methods and look at the linked answers to gain further enlightenment. – Grax32 Apr 08 '19 at 19:08

0 Answers0