public Expression<Func<Job, bool>> ToLambda()
{
Type type = typeof (Job);
ParameterExpression parameterExpression = Expression.Parameter(type, "job");
Expression body = Expression.Equal(Expression.Property(parameterExpression, "MemberId"), Expression.Constant(MemberId));
if (Key.IsNotNullAndWhiteSpace())
{
MemberExpression keyMember = Expression.Property(parameterExpression, "JobName");
Expression value = Expression.Constant(Key);
MethodCallExpression keyExpression = Expression.Call(keyMember,
typeof (string).GetMethod("Contains"),
value);
body = Expression.And(body, keyExpression);
}
if(IsOpen.HasValue)
{
MemberExpression isOpenExpression = Expression.Property(parameterExpression, "IsOpen");
Expression openExpression = Expression.Equal(isOpenExpression, Expression.Constant(IsOpen));
body = Expression.And(body, openExpression);
}
return Expression.Lambda<Func<Job, bool>>(body, parameterExpression);
}