public static void ArrayInitializer() { ExpressionTrees.Test((Func <int[]>)(() => new int[3] { 1, 2, 3 }), (Expression <Func <int[]> >)(() => new int[3] { 1, 2, 3 })); ExpressionTrees.Test((Func <int[]>)(() => new int[3]), (Expression <Func <int[]> >)(() => new int[3])); ExpressionTrees.Test((Func <int[, ]>)(() => new int[3, 5]), (Expression <Func <int[, ]> >)(() => new int[3, 5])); ExpressionTrees.Test((Func <int[][]>)(() => new int[3][]), (Expression <Func <int[][]> >)(() => new int[3][])); ExpressionTrees.Test((Func <int[][]>)(() => new int[1][] { new int[3] { 1, 2, 3 } }), (Expression <Func <int[][]> >)(() => new int[1][] { new int[3] { 1, 2, 3 } })); }
public static void ShiftOperators() { ExpressionTrees.Test((Func <int, int>)((int a) => a >> 2), (Expression <Func <int, int> >)((int a) => a >> 2)); ExpressionTrees.Test((Func <int, int>)((int a) => a << 2), (Expression <Func <int, int> >)((int a) => a << 2)); ExpressionTrees.Test((Func <long, long>)((long a) => a >> 2), (Expression <Func <long, long> >)((long a) => a >> 2)); ExpressionTrees.Test((Func <long, long>)((long a) => a << 2), (Expression <Func <long, long> >)((long a) => a << 2)); }
public static void BitOperators() { ExpressionTrees.Test((Func <int, int>)((int a) => ~a), (Expression <Func <int, int> >)((int a) => ~a)); ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a & b), (Expression <Func <int, int, int> >)((int a, int b) => a & b)); ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a | b), (Expression <Func <int, int, int> >)((int a, int b) => a | b)); ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a ^ b), (Expression <Func <int, int, int> >)((int a, int b) => a ^ b)); }
public static void Call() { ExpressionTrees.ToCode(null, (string a) => Console.WriteLine(a)); ExpressionTrees.Test((Func <string, string>)((string a) => a.ToString()), (Expression <Func <string, string> >)((string a) => a.ToString())); ExpressionTrees.Test((Func <int, string>)((int a) => a.ToString()), (Expression <Func <int, string> >)((int a) => a.ToString())); ExpressionTrees.Test((Func <string, char[]>)((string a) => a.ToArray()), (Expression <Func <string, char[]> >)((string a) => a.ToArray())); ExpressionTrees.Test((Func <bool>)(() => 'a'.CompareTo('b') < 0), (Expression <Func <bool> >)(() => 'a'.CompareTo('b') < 0)); }
public unsafe static void TypeOfExpr() { ExpressionTrees.Test((Func <Type>)(() => typeof(int)), (Expression <Func <Type> >)(() => typeof(int))); ExpressionTrees.Test((Func <Type>)(() => typeof(object)), (Expression <Func <Type> >)(() => typeof(object))); ExpressionTrees.Test((Func <Type>)(() => typeof(List <>)), (Expression <Func <Type> >)(() => typeof(List <>))); ExpressionTrees.Test((Func <Type>)(() => typeof(List <int>)), (Expression <Func <Type> >)(() => typeof(List <int>))); ExpressionTrees.Test((Func <Type>)(() => typeof(int *)), (Expression <Func <Type> >)(() => typeof(int *))); }
public static void ArrayIndexer() { ExpressionTrees.Test((Func <int[], int>)((int[] array) => array[0]), (Expression <Func <int[], int> >)((int[] array) => array[0])); ExpressionTrees.Test((Func <int[], int, int>)((int[] array, int index) => array[index]), (Expression <Func <int[], int, int> >)((int[] array, int index) => array[index])); ExpressionTrees.Test((Func <int[, ], int>)((int[,] array) => array[0, 5]), (Expression <Func <int[, ], int> >)((int[,] array) => array[0, 5])); ExpressionTrees.Test((Func <int[, ], int, int>)((int[,] array, int index) => array[index, 7]), (Expression <Func <int[, ], int, int> >)((int[,] array, int index) => array[index, 7])); ExpressionTrees.Test((Func <int[][], int, int>)((int[][] array, int index) => array[index][7]), (Expression <Func <int[][], int, int> >)((int[][] array, int index) => array[index][7])); }
public static void NewObj() { ExpressionTrees.Test((Func <object>)(() => new SimpleType()), (Expression <Func <object> >)(() => new SimpleType())); ExpressionTrees.Test((Func <object>)(() => new SimpleTypeWithCtor(5)), (Expression <Func <object> >)(() => new SimpleTypeWithCtor(5))); ExpressionTrees.Test((Func <object>)(() => new SimpleTypeWithMultipleCtors()), (Expression <Func <object> >)(() => new SimpleTypeWithMultipleCtors())); ExpressionTrees.Test((Func <object>)(() => new SimpleTypeWithMultipleCtors(5)), (Expression <Func <object> >)(() => new SimpleTypeWithMultipleCtors(5))); ExpressionTrees.Test((Func <object>)(() => new GenericClass <int>()), (Expression <Func <object> >)(() => new GenericClass <int>())); ExpressionTrees.Test((Func <object>)(() => new GenericClassWithCtor <int>()), (Expression <Func <object> >)(() => new GenericClassWithCtor <int>())); ExpressionTrees.Test((Func <object>)(() => new GenericClassWithMultipleCtors <int>(5)), (Expression <Func <object> >)(() => new GenericClassWithMultipleCtors <int>(5))); }
public static void AnonymousTypes() { ExpressionTrees.Test((Func <object>)(() => new { A = 5, B = "Test" }), (Expression <Func <object> >)(() => new { A = 5, B = "Test" })); }
public static void BinaryArithmeticOperators() { ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a + b), (Expression <Func <int, int, int> >)((int a, int b) => a + b)); ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a - b), (Expression <Func <int, int, int> >)((int a, int b) => a - b)); ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a * b), (Expression <Func <int, int, int> >)((int a, int b) => a * b)); ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a / b), (Expression <Func <int, int, int> >)((int a, int b) => a / b)); ExpressionTrees.Test((Func <int, int, int>)((int a, int b) => a % b), (Expression <Func <int, int, int> >)((int a, int b) => a % b)); ExpressionTrees.Test((Func <long, int, long>)((long a, int b) => a + b), (Expression <Func <long, int, long> >)((long a, int b) => a + (long)b)); ExpressionTrees.Test((Func <long, int, long>)((long a, int b) => a - b), (Expression <Func <long, int, long> >)((long a, int b) => a - (long)b)); ExpressionTrees.Test((Func <long, int, long>)((long a, int b) => a * b), (Expression <Func <long, int, long> >)((long a, int b) => a * (long)b)); ExpressionTrees.Test((Func <long, int, long>)((long a, int b) => a / b), (Expression <Func <long, int, long> >)((long a, int b) => a / (long)b)); ExpressionTrees.Test((Func <long, int, long>)((long a, int b) => a % b), (Expression <Func <long, int, long> >)((long a, int b) => a % (long)b)); ExpressionTrees.Test((Func <short, int, int>)((short a, int b) => a + b), (Expression <Func <short, int, int> >)((short a, int b) => a + b)); ExpressionTrees.Test((Func <int, short, int>)((int a, short b) => a - b), (Expression <Func <int, short, int> >)((int a, short b) => a - b)); ExpressionTrees.Test((Func <short, int, int>)((short a, int b) => a * b), (Expression <Func <short, int, int> >)((short a, int b) => a * b)); ExpressionTrees.Test((Func <int, short, int>)((int a, short b) => a / b), (Expression <Func <int, short, int> >)((int a, short b) => a / b)); ExpressionTrees.Test((Func <short, int, int>)((short a, int b) => a % b), (Expression <Func <short, int, int> >)((short a, int b) => a % b)); }
public static void AsTypeExpr() { ExpressionTrees.Test((Func <object, MyClass>)((object obj) => obj as MyClass), (Expression <Func <object, MyClass> >)((object obj) => obj as MyClass)); ExpressionTrees.Test((Func <object, GenericClass <object> >)((object obj) => obj as GenericClass <object>), (Expression <Func <object, GenericClass <object> > >)((object obj) => obj as GenericClass <object>)); }
public static void IsTypeExpr() { ExpressionTrees.Test((Func <object, bool>)((object obj) => obj is MyClass), (Expression <Func <object, bool> >)((object obj) => obj is MyClass)); }
public static void Quote() { ExpressionTrees.Test((Func <bool>)(() => (Expression <Func <int, string, string> >)((int n, string s) => s + n.ToString()) != null), (Expression <Func <bool> >)(() => (Expression <Func <int, string, string> >)((int n, string s) => s + n.ToString()) != null)); }
public static void Capturing() { int captured = 5; ExpressionTrees.Test((Func <int>)(() => captured), (Expression <Func <int> >)(() => captured)); }
public static void SimpleExpressions() { ExpressionTrees.Test((Func <int>)(() => 0), (Expression <Func <int> >)(() => 0)); ExpressionTrees.Test((Func <int, int>)((int a) => a), (Expression <Func <int, int> >)((int a) => a)); }
public static void UnaryLogicalOperators() { ExpressionTrees.Test((Func <bool, bool>)((bool a) => !a), (Expression <Func <bool, bool> >)((bool a) => !a)); }
public static void UnaryArithmeticOperators() { ExpressionTrees.Test((Func <int, int>)((int a) => a), (Expression <Func <int, int> >)((int a) => a)); ExpressionTrees.Test((Func <int, int>)((int a) => - a), (Expression <Func <int, int> >)((int a) => - a)); }
public static void ArrayLength() { ExpressionTrees.Test((Func <int[], int>)((int[] array) => array.Length), (Expression <Func <int[], int> >)((int[] array) => array.Length)); ExpressionTrees.Test((Func <int>)(() => ((Array)null).Length), (Expression <Func <int> >)(() => ((Array)null).Length)); }