Upcoming SlideShare
×

# Expression trees

1,195 views

Published on

Express presentation about expression trees

Published in: Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

Views
Total views
1,195
On SlideShare
0
From Embeds
0
Number of Embeds
65
Actions
Shares
0
15
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Expression trees

1. 1. Expression Trees<br />How to…<br />YuriySeniuk<br />http://yuriyseniuk.blogspot.com/<br />
2. 2. What is Expression Trees<br />Is a Tree<br />Has 56 Expressions<br />Add, Bind, Block, Break, Call, Catch, Coalesce, Continue, Equal, GreaterThan, Lambda, Loop, New, Or , PowerAssign ……………<br />Expression: 5 + 4 * 3<br />+<br />5<br />*<br />4<br />3<br />
3. 3. How to Build?<br />Func<int, int> myDelegate = (a, b) => a + b; <br />Expression<Func<int, int>> myExpression = (a, b) => a + b;<br />BinaryExpressionmyExpression = <br />Expression.Add( Expression.Constant( 2 ), Expression.Constant( 5 ) );<br />
4. 4. How to Use?<br />BinaryExpressionmyExpression = Expression.Add( Expression.Constant( 2 ), Expression.Constant( 5 ) );<br />var compiled = Expression.Lambda<Func<int>>( myExpression ).Compile();<br />compiled();<br />Expression<Func<int, bool>> expr = num => num < 5; <br />Func<int, bool> compiled = expr.Compile();<br />compiled (4);<br />
5. 5. Where can be useful?<br />Dynamic code;<br />Object cloning;<br />Alternative for reflection;<br />Transform a domain language into executable code;<br />Patterns code improvement.<br />
6. 6. Any questions?<br />?<br />
7. 7. Links<br />http://habrahabr.ru/blogs/net/83169/<br />http://www.i-programmer.info/programming/c/869-lambda-expressions-expressiontrees.html?start=1<br />http://www.abhisheksur.com/2010/09/use-of-expression-trees-in-lamda-c.html<br />http://geekswithblogs.net/Martinez/articles/understanding-expression-trees.aspx<br />http://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.aspx<br />