private void ProcessOrderClause(LambdaExpression lambda, bool isAscending) { if ((lambda.Parameters.Count != 1) || (!(lambda.Parameters[0] is ParameterExpression)) || (!IsAWorkItem(lambda.Parameters[0].Type))) { throw new InvalidOperationException("invalid order clase"); } Expression body = lambda.Body; MemberExpression me = body as MemberExpression; string fieldReference = null; if (me != null) { fieldReference = FieldUtility.ExtractFieldReferenceName(me.Member); if (fieldReference == null) { throw new InvalidOperationException("invalid order field"); } _builder.AddOrderClause(fieldReference, isAscending); return; } MethodCallExpression mc = body as MethodCallExpression; if (mc != null) { fieldReference = FieldUtility.ExtractWIFieldFromMethodCall(mc); if (fieldReference == null) { throw new InvalidOperationException("invalid order field"); } _builder.AddOrderClause(fieldReference, isAscending); } }
protected override Expression VisitMethodCall(MethodCallExpression m) { if ((m.Object is ParameterExpression) && (m.Object.Type == typeof(WIT.WorkItem))) { if (CurrentLocation != WhereLocationEnum.LeftOperatorClause) { throw new InvalidOperationException("Methodcall"); } string fieldReference = FieldUtility.ExtractWIFieldFromMethodCall(m); if (fieldReference == null) { throw new NotSupportedException("MethodCall"); } _builder.Append(fieldReference); } else if (CheckCustomOperatorCalls(m)) { return(m); } else if (CheckCustomStaticOperatorCalls(m)) { return(m); } //else if (CheckFieldExtensionMethodCall(m)) //{ // return m; //} else { MemberExpression me = m.Object as MemberExpression; if ((me == null) || (!(me.Expression is ParameterExpression)) || (m.Arguments.Count != 1)) { throw new NotSupportedException("MethodCall"); } else { ConstantExpression constant = m.Arguments[0] as ConstantExpression; string op = null; if (me.Type == typeof(string)) { if (m.Method.Name == "Contains") { op = "CONTAINS"; } else if (m.Method.Name == "StartsWith") { op = "UNDER"; } } if (op == null) { throw new NotSupportedException("MethodCall"); } PushLocation(WhereLocationEnum.LeftOperatorClause); Visit(me); PopLocation(); _builder.Append(" " + op + " "); PushLocation(WhereLocationEnum.RightOperatorClause); Visit(m.Arguments[0]); PopLocation(); } } return(m); }