-
Notifications
You must be signed in to change notification settings - Fork 11
ExpressionTreeTestObjects
Expression trees (and related objects) can be written in three ways:
- The C# compiler
- The VB compiler
- Factory methods at System.Linq.Expressions.Expression
As part of the development of this project, I needed a comprehensive set of expression trees to test the formatters against. This set of objects is available as a Nuget package.
Each expression object is a field with the TestObject attribute applied to it.
The objects are available by referencing the NuGet package, and calling the static Get method:
// using ExpressionTreeTestObjects;
(string category, string source, string name, object o)[] lst = Objects.Get();
where source is the type where the object is defined -- one of the following:
| Source | Description |
|---|---|
CSCompiler |
C# compiler |
VBCompiler |
VB compiler |
Factory methods |
Factory methods |
and category is one of these values:
BinaryBlocksConditionalsConstantsDebugInfosDefaultsDynamicsGotosIndexerInvocationLabelsLambdaLiteralLoopsMember access (+ closed variables)Member bindingsMethod callNew arrayObject creation and initializationQuotedRuntime variablesSwitch, CatchBlockTry, Catch, FinallyType checkUnary
The static constructor automatically loads types in assemblies that start with ExpressionTreeTestObjects -- ExpressionTreeTestObjects.CSharp.dll, and ExpressionTreeTestObjects.VB.dll. However, if you want to add your own fields, you can call the static LoadType method with your own types:
Objects.LoadType(typeof(MyCustomType));
and it will add the object. The type name becomes the source, and the field name becomes the objectName.
The C# and VB compiler test expressions were added as I was working on the corresponding formatters. For the factory methods, I used reflection to build a list of all the methods and overloads at System.Linq.Expressions.Expression and created expressions by calling each one.
The result is pretty comprehensive, with one limitation: I didn't write test expressions for overloads which take an additional MethodInfo, like this one. This is being tracked at #20