protected override Expression VisitMemberAccess(MemberExpression m) { ParameterExpression param = m.Expression as ParameterExpression; if (param != null) { if (CurrentLocation != WhereLocationEnum.LeftOperatorClause) { throw new NotSupportedException("Member position not supported"); } string fieldRefName = FieldUtility.ExtractFieldReferenceName(m.Member); if (fieldRefName != null) { _builder.Append(fieldRefName); return(m); } } if (m.Member.DeclaringType == typeof(QueryConstant)) { if (CurrentLocation != WhereLocationEnum.RightOperatorClause) { throw new NotSupportedException("Member position not supported"); } _builder.Append("@" + m.Member.Name); return(m); } if ((m.Member.DeclaringType == typeof(WIT.Field)) && (m.Member.Name == "Value")) { string fieldRefName; if (LinqRegexp.TryGetFieldRefNameFromExpression(m, out fieldRefName)) { _builder.AppendFormat("[{0}]", fieldRefName); return(m); } } throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name)); }
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); }