2 using System.Collections.Generic;
3 using System.Linq.Expressions;
7 namespace Deveel.Data.Linq {
13 public static new string Format(Expression expression) {
19 formatter.Visit(expression);
20 return formatter.ToString();
23 protected override Expression
VisitSelect(SelectExpression @select) {
24 AddAliases(select.From);
28 if (select.IsDistinct)
31 WriteColumns(select.Columns);
33 if (select.From != null) {
34 WriteLine(Indentation.Same);
36 VisitSource(select.From);
39 if (select.Where != null &&
40 (select.GroupBy == null || select.GroupBy.Count ==0)) {
41 WriteLine(Indentation.Same);
43 VisitPredicate(select.Where);
46 if (select.GroupBy != null && select.GroupBy.Count > 0) {
47 WriteLine(Indentation.Same);
50 for (
int i = 0, n = select.GroupBy.Count; i < n; i++) {
55 VisitValue(select.GroupBy[i]);
58 if (select.Where != null) {
59 WriteLine(Indentation.Same);
61 VisitPredicate(select.Where);
64 if (select.OrderBy != null && select.OrderBy.Count > 0) {
65 WriteLine(Indentation.Same);
68 for (
int i = 0, n = select.OrderBy.Count; i < n; i++) {
69 OrderExpression exp = select.OrderBy[i];
74 VisitValue(exp.Expression);
76 if (exp.OrderType != OrderType.Ascending)
81 if (select.Take != null) {
82 WriteLine(Indentation.Same);
84 if (select.Skip == null) {
98 if (b.NodeType == ExpressionType.Add && b.Type == typeof (
string))
101 return base.GetOperator(b);
105 var declaringType = m.Method.DeclaringType;
107 if (declaringType == typeof (
string)) {
108 switch (m.Method.Name) {
112 Visit(m.Arguments[0]);
119 Visit(m.Arguments[0]);
126 Visit(m.Arguments[0]);
131 IList<Expression> args = m.Arguments;
132 if (args.Count == 1 && args[0].NodeType == ExpressionType.NewArrayInit) {
133 args = ((NewArrayExpression) args[0]).Expressions;
135 for (
int i = 0, n = args.Count; i < n; i++) {
144 case "IsNullOrEmpty": {
145 Visit(m.Arguments[0]);
146 Write(
" IS NULL OR ");
147 Visit(m.Arguments[0]);
154 return base.VisitMethodCall(m);
158 var declaringType = m.Member.DeclaringType;
159 if (declaringType == typeof (
string)) {
160 switch (m.Member.Name) {
168 }
else if (declaringType == typeof (DateTime) ||
169 declaringType == typeof (DateTimeOffset)) {
170 switch (m.Member.Name) {
185 }
else if (declaringType == typeof (TimeSpan)) {
189 return base.VisitMemberAccess(m);