LINQ in not only for Object Query

LINQ in not only for Object Query

  • Comments 1

 

Hello all,

 

Here we will explore another side of LINQ (Language-INtegrated Query). We all know that LINQ is to query the object (even to the System object). Using the System.Reflection namespace we can get the list of Methods, Fields etc using LINQ Query (with the filter and sort). Lets see one small example on that,

 

IEnumerable<Type> all = from t in typeof(SqlConnection).Assembly.GetTypes()

                        where t.Name == "SqlConnection"                                   

                        orderby t.Name

                        select t;

 

foreach(var v in all)

{

    textBox1.Text += "Start:Methods of " +  v.Name   + "\r\n";

    textBox1.Text += "===================================\r\n";

    foreach(MemberInfo mi in v.GetMembers())

        textBox1.Text += mi.Name   + "\r\n";

}

 

The output will display the list of methods from the SqlConnection class.

 

Namoskar

 

Leave a Comment
  • Please add 6 and 1 and type the answer here:
  • Post
  • Nice example

    Thanks

    Mahir M. Quluzade

Page 1 of 1 (1 items)