c# - Trying to create a "Fluent" type class using LINQ expressions -


i'd follows, using lambdas , linq expressions in c#.

 public class foo {     private someentity entity;     public foo(someentity entity)     {         this.entity = entity;         bar(p => p.firstname);         bar(p => p.surname);     }      public void bar(expression> barexpression)     {         // here?     } } 

every time call bar(), i'd dig expression, , find out property referring (e.g. firstname or lastname), , someentity object working with. need value of property (this in fact important).

eventually i'd extend bar more this, simple can "boil" experiment.

thanks!

public void bar<t>(expression<func<someentity, t>> expression) {     string name = ((memberexpression)expression.body).member.name; } 

should name; there no instance in p => p.firstname; this.entity should give want. value t value = expression.compile()(entity)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -