通用 Lambda 查詢生成器
這個類叫做 ExpressionBuilder。它有三個屬性:
private static readonly MethodInfo ContainsMethod = typeof(string).GetMethod("Contains", new[] { typeof(string) });
private static readonly MethodInfo StartsWithMethod = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
private static readonly MethodInfo EndsWithMethod = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
一個返回 lambda 表示式的公共方法 GetExpression 和三個私有方法:
Expression GetExpression<T>BinaryExpression GetExpression<T>ConstantExpression GetConstant
所有方法都在實施例中詳細解釋。