Skip to content
Sample code for MSDN article "Expression Trees in Visual Basic and C#"
C# Visual Basic
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
CSharp Reorder samples based on article order; added NodeType Value Name sample Aug 26, 2019
CSharp_LikeVisitor Complete mapping of VB Like to SQL Like Aug 28, 2019
CSharp_SetColumns VB.NET workarounds for pattern matching and tuple unpacking Aug 26, 2019
Shared Complete mapping of VB Like to SQL Like Aug 28, 2019
VisualBasic Reorder samples based on article order; added NodeType Value Name sample Aug 26, 2019
VisualBasic_LikeVisitor Complete mapping of VB Like to SQL Like Aug 28, 2019
VisualBasic_SetColumns VB SetColumns Aug 26, 2019
_InsertDataAndConnectionTest
_Shared.EF6 Complete LikeVisitor samples Aug 26, 2019
_Tests Complete mapping of VB Like to SQL Like Aug 28, 2019
.gitattributes
.gitignore Add .gitignore and .gitattributes. Jul 18, 2019
.markdownlint.json Updated README Aug 26, 2019
ExpressionTreesInVBandCS.sln Complete mapping of VB Like to SQL Like Aug 28, 2019
LICENSE Create LICENSE Aug 26, 2019
People.db
README.md Update README.md Sep 19, 2019

README.md

Sample code for Expression Trees in Visual Basic and C#

This repo contains accompanying samples for Expression Trees in Visual Basic and C#, an MSDN Magazine article which appeared in the September 2019 issue.

All the samples are available in both a C# version and a VB.NET version (except for the sample demonstrating the usage of the Like operator rewrite, because C# doesn't have the Like operator).

The samples, in order of appearance in the article, are as follows:

Figure Name/Description Location
2 Expression Tree Objects Using Object Notation
Shows an expression tree using object and collection initialization syntax
CSharp
VisualBasic
3 NodeType, Value, Name properties
Shows the properties relevant to understanding the structure of an expression tree
CSharp
VisualBasic
5 Blocks, Assignments and Statements in Expression Trees
Constructs an expression tree using factory methods, interspersed with the corresponding code in comments
CSharp
VisualBasic
6 Visualization of Final Expression Tree
Demonstrates what an expression tree looks like before and after a call to Queryable.Where
CSharp
VisualBasic
7 Requests Using the Simple.OData.Client Library and Expression Trees CSharp
VisualBasic
GetMethod -- Reflection by Example
Uses an expression tree to target a specific MethodInfo instead of reflection
CSharp
VisualBasic
Grid Column Configuration
Declaratively set the columns of a WPF DataGrid using an appropriate expression
CSharp_SetColumns
VisualBasic_SetColumns
8 ExpressionTreeVisitor Replacing Visual Basic's Like with DbFunctions.Like CSharp_LikeVisitor
VisualBasic_LikeVisitor

Description of the project structure

Projects whose name starts with CSharp contain C# versions of the samples; projects starting with VisualBasic contain Visual Basic versions.

The project structure is as follows:

Project name Description
_Shared Contains shared code used by multiple samples, e.g. data classes and extensions
_Shared.EF6 The LikeVisitor sample uses EF6. This project contains the DbContext and configuration classes
CSharp
VisualBasic
Short samples, each of which is encapsulated in a single method
CSharp_SetColumn
VisualBasic_SetColumn
  • Implements declaratively setting columns on a WPF DataGrid in code, using expression trees
  • ParseFields -- Parses the intended columns from an expression returning an array, anonymous type, or single property
  • XamlBindingPathVisitor -- Expression visitor that generates an object path usable with WPF databinding
CSharp_LikeVisitor
VisualBasic_LikeVisitor
Uses an expression visitor to rewrite Visual Basic's Like operator usages to EF's DbFunctions.Like method.
Note that while the visitor is implemented in both C# and Visual Basic, the calling code is only in Visual Basic, as C# doesn't have the Like operator

TODO

  • DLR CallSite
You can’t perform that action at this time.