Exemple #1
0
 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
         }
     }));
 }
Exemple #2
0
 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));
 }
Exemple #3
0
 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));
 }
Exemple #4
0
 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));
 }
Exemple #5
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 *)));
 }
Exemple #6
0
 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]));
 }
Exemple #7
0
 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)));
 }
Exemple #8
0
 public static void AnonymousTypes()
 {
     ExpressionTrees.Test((Func <object>)(() => new {
         A = 5,
         B = "Test"
     }), (Expression <Func <object> >)(() => new {
         A = 5,
         B = "Test"
     }));
 }
Exemple #9
0
 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));
 }
Exemple #10
0
 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>));
 }
Exemple #11
0
 public static void IsTypeExpr()
 {
     ExpressionTrees.Test((Func <object, bool>)((object obj) => obj is MyClass), (Expression <Func <object, bool> >)((object obj) => obj is MyClass));
 }
Exemple #12
0
 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));
 }
Exemple #13
0
        public static void Capturing()
        {
            int captured = 5;

            ExpressionTrees.Test((Func <int>)(() => captured), (Expression <Func <int> >)(() => captured));
        }
Exemple #14
0
 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));
 }
Exemple #15
0
 public static void UnaryLogicalOperators()
 {
     ExpressionTrees.Test((Func <bool, bool>)((bool a) => !a), (Expression <Func <bool, bool> >)((bool a) => !a));
 }
Exemple #16
0
 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));
 }
Exemple #17
0
 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));
 }