c# - Generic query in Linq -


i want make generic search usercontrol in wpf. want collection of objects , name of property search by. problem can't use generics because code calls search function can't know of type.

is there way achieve this? or way query object underneath type?

consider example.

interface ifoo     {      }     class bar1 : ifoo     {         //interface implementations         public string property1 { get; set; }          public string myproperty1 { set; get; }     }      class bar2 : ifoo     {         //interface implementations         public string property1 { get; set; }          public string myproperty1 { set; get; }     }       //search list of objects , access original values.     list<ifoo> foos = new list<ifoo>();         foos.add(new bar1         {             property1 = "bar1",             myproperty1 ="mybar1"         });         foos.add(new bar1());          foos.add(new bar2());         foos.add(new bar2());          //get objects.         foreach (var foo in foos)         {             //you can access foo directly without knowing original class.             var fooproperty = foo.property1;              //you have use reflection original type , properties , methods             type type = foo.gettype();             foreach (var propertyinfo in type.getproperties())             {                 var propname = propertyinfo.name;                 var propvalue = propertyinfo.getvalue(foo);             }         }   var result = list.where(a => a.propertyname); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -