1: private static readonly Dictionary<QueryMethod, Func<Expression, Expression, Expression>> ExpressionDict =
2: new Dictionary<QueryMethod, Func<Expression, Expression, Expression>>
3: {
4: {
5: QueryMethod.Equal,
6: (left, right) => { return Expression.Equal(left, right); }
7: },
8: {
9: QueryMethod.GreaterThan,
10: (left, right) => { return Expression.GreaterThan(left, right); }
11: },
12: {
13: QueryMethod.GreaterThanOrEqual,
14: (left, right) => { return Expression.GreaterThanOrEqual(left, right); }
15: },
16: {
17: QueryMethod.LessThan,
18: (left, right) => { return Expression.LessThan(left, right); }
19: },
20: {
21: QueryMethod.LessThanOrEqual,
22: (left, right) => { return Expression.LessThanOrEqual(left, right); }
23: },
24: {
25: QueryMethod.Contains,
26: (left, right) =>
27: {
28: if (left.Type != typeof (string)) return null;
29: return Expression.Call(left, typeof (string).GetMethod("Contains"), right);
30: }
31: },
32: {
33: QueryMethod.StdIn,
34: (left, right) =>
35: {
36: if (!right.Type.IsArray) return null;
37: //调用Enumerable.Contains扩展方法
38: MethodCallExpression resultExp =
39: Expression.Call(
40: typeof (Enumerable),
41: "Contains",
42: new[] {left.Type},
43: right,
44: left);
45:
46: return resultExp;
47: }
48: },
49: {
50: QueryMethod.NotEqual,
51: (left, right) => { return Expression.NotEqual(left, right); }
52: },
53: {
54: QueryMethod.StartsWith,
55: (left, right) =>
56: {
57: if (left.Type != typeof (string)) return null;
58: return Expression.Call(left, typeof (string).GetMethod("StartsWith", new[] {typeof (string)}), right);
59:
60: }
61: },
62: {
63: QueryMethod.EndsWith,
64: (left, right) =>
65: {
66: if (left.Type != typeof (string)) return null;
67: return Expression.Call(left, typeof (string).GetMethod("EndsWith", new[] {typeof (string)}), right);
68: }
69: },
70: {
71: QueryMethod.DateTimeLessThanOrEqual,
72: (left, right) => { return Expression.LessThanOrEqual(left, right); }
73: }
74: };