c# - Get value from expression in linq extension method -


i searched whole internet , tried many things, not able value expression. cool if me...

bye markus

public static class linqextension {     public static iqueryable<t> getfilteredbystatuslist<t>(this iqueryable<t> source, expression<func<t, int>> expression)     {         // can compile expression.         // in posts have found, have call compiled method, method needs t object.         // have no idea how acces value of t.         func<t, int> method = expression.compile();             //edit             // here need int value pass in service method like:             // service.getstatusbyid("int value expression");             //edit end         return source;     } } 

-- edit have query , in query have call method needs dynamic value current query item. method exists , work after query loop through query , call method on every item in loop. think not fast solution.

so call method inside query , why try implement extension method.

following extension method call:

return query = query             .join(entities.tbltaskgroupglobal, x => x.lngassignmain_id, y => y.id, (x, y) => new { x = x, y = y })             .whereif(taskfiltermodel.statusfilterlist.count() > 0, xy => taskfiltermodel.statusfilterlist.contains(xy.y.lngconstantstatus_id))             .getfilteredbystatuslist(xy => xy.x.lngassignmain_id)             .select(xy => xy.x); 

-- edit end

wow, whole internet! must have taken while! :)

the expression have compiled expecting take object of type t , return value of type int.

i imagine want enumerate source , apply method it.

for example:

foreach (t item in source) {      yield return method(item); } 

but think better question - how planning use method? sure expression need?


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -