SlideShare a Scribd company logo
1 of 11
Expression Tree
Jason
Expression tree
Expression trees represent code in a tree-like data structure, where each node is
an expression.
This enables dynamic modification of executable code, the execution of LINQ
queries in various databases, and the creation of dynamic queries.
Lambda
Statement lambda
(x, y) => { return x + y; }
Expression lambda
(x, y) => x + y
Lambda Expression
Using the System.Linq.Expressions namespace
Expression<Func<int, bool>> expr = n => n > 5;
Expression<TDelegate>.Compile
Compile the expression tree into executable code.
Expression<Func<int, bool>> expr = n => n > 5;
Func<int, bool> deleg = expr.Compile();
deleg(3);
Expression<Func<int, bool>>
n => n > 5
Body : BinaryExpression
n > 5
Left : Expression
n
Right : Expression
5
NodeType : ExpressionType
GreaterThan
NodeType : ExpressionType
Lambda
ReturnType : Type
Boolean
ParameterExpression
ParameterExpression iParam =
Expression.Parameter(typeof(int), "n");
>
n 5
λ
BinaryExpression
BinaryExpression binaryExpr =
Expression.GreaterThan(iParam, constantExpr);
>
n 5
λ
ConstantExpression
ConstantExpression constantExpr =
Expression.Constant(5, typeof(int));
>
n 5
λ
LambdaExpression
Expression<Func<int, bool>> expr =
Expression.Lambda<Func<int, bool>>(binaryExpr, iParam);
>
n 5
λ
Reference
Expression Tree - MSDN
https://msdn.microsoft.com/en-us/library/bb397951.aspx

More Related Content

What's hot

Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 

What's hot (19)

Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
Programming in Scala - Lecture Four
Programming in Scala - Lecture FourProgramming in Scala - Lecture Four
Programming in Scala - Lecture Four
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
Unit v
Unit vUnit v
Unit v
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 
Compiler notes--unit-iii
Compiler notes--unit-iiiCompiler notes--unit-iii
Compiler notes--unit-iii
 
C intro
C introC intro
C intro
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
C# String
C# StringC# String
C# String
 
Ch13
Ch13Ch13
Ch13
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
expressions
expressionsexpressions
expressions
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 

Viewers also liked (19)

Power shell object
Power shell objectPower shell object
Power shell object
 
Bootstrap–component
Bootstrap–componentBootstrap–component
Bootstrap–component
 
Vic weekly learning_20151120
Vic weekly learning_20151120Vic weekly learning_20151120
Vic weekly learning_20151120
 
React.js 20150828
React.js 20150828React.js 20150828
React.js 20150828
 
20121228 jqueryui - button - By Nat
20121228 jqueryui - button - By Nat20121228 jqueryui - button - By Nat
20121228 jqueryui - button - By Nat
 
20120601_Excel 元件 ep plus joncash
20120601_Excel 元件 ep plus joncash20120601_Excel 元件 ep plus joncash
20120601_Excel 元件 ep plus joncash
 
JSRender
JSRenderJSRender
JSRender
 
Covariance, contravariance 觀念分享
Covariance, contravariance 觀念分享Covariance, contravariance 觀念分享
Covariance, contravariance 觀念分享
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Mvc route
Mvc routeMvc route
Mvc route
 
20121228 jQueryui - datepicker - By Jason
20121228 jQueryui - datepicker - By Jason20121228 jQueryui - datepicker - By Jason
20121228 jQueryui - datepicker - By Jason
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 
20120601_jquery tree traversal_drake
20120601_jquery tree traversal_drake20120601_jquery tree traversal_drake
20120601_jquery tree traversal_drake
 
What is new in visual studio 2015
What is new in visual studio 2015What is new in visual studio 2015
What is new in visual studio 2015
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
PostCss
PostCssPostCss
PostCss
 
Expression tree
Expression treeExpression tree
Expression tree
 
ReactJs
ReactJsReactJs
ReactJs
 

Similar to Expression tree

Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 

Similar to Expression tree (20)

Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
C# programming
C# programming C# programming
C# programming
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
04_python_functions.ppt You can define functions to provide the required func...
04_python_functions.ppt You can define functions to provide the required func...04_python_functions.ppt You can define functions to provide the required func...
04_python_functions.ppt You can define functions to provide the required func...
 
Linq and lambda
Linq and lambdaLinq and lambda
Linq and lambda
 
Functions & Closures in Scala
Functions & Closures in ScalaFunctions & Closures in Scala
Functions & Closures in Scala
 
Functions & Closures in Scala
Functions & Closures in ScalaFunctions & Closures in Scala
Functions & Closures in Scala
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
 
Testing for share
Testing for share Testing for share
Testing for share
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
 
Lesson11
Lesson11Lesson11
Lesson11
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 
CC Week 11.ppt
CC Week 11.pptCC Week 11.ppt
CC Week 11.ppt
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional Programming
 

More from LearningTech (20)

vim
vimvim
vim
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 
Asp.net MVC DI
Asp.net MVC DIAsp.net MVC DI
Asp.net MVC DI
 
Vic weekly learning_20151127
Vic weekly learning_20151127Vic weekly learning_20151127
Vic weekly learning_20151127
 
Mocha.js
Mocha.jsMocha.js
Mocha.js
 
R language
R languageR language
R language
 
20151120 ian cocos2d js
20151120 ian cocos2d js20151120 ian cocos2d js
20151120 ian cocos2d js
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 

Recently uploaded

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Expression tree

Editor's Notes

  1. https://msdn.microsoft.com/zh-tw/library/bb361179(v=vs.110).aspx