comparison Source/Data/Sql/SqlBinaryExpression.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.Text;
5
6 namespace BLToolkit.Data.Sql
7 {
8 [Serializable, DebuggerDisplay("SQL = {SqlText}")]
9 public class SqlBinaryExpression : ISqlExpression
10 {
11 public SqlBinaryExpression(Type systemType, ISqlExpression expr1, string operation, ISqlExpression expr2, int precedence)
12 {
13 if (expr1 == null) throw new ArgumentNullException("expr1");
14 if (operation == null) throw new ArgumentNullException("operation");
15 if (expr2 == null) throw new ArgumentNullException("expr2");
16
17 Expr1 = expr1;
18 Operation = operation;
19 Expr2 = expr2;
20 SystemType = systemType;
21 Precedence = precedence;
22 }
23
24 public SqlBinaryExpression(Type systemType, ISqlExpression expr1, string operation, ISqlExpression expr2)
25 : this(systemType, expr1, operation, expr2, Sql.Precedence.Unknown)
26 {
27 }
28
29 public ISqlExpression Expr1 { get; internal set; }
30 public string Operation { get; private set; }
31 public ISqlExpression Expr2 { get; internal set; }
32 public Type SystemType { get; private set; }
33
34 public int Precedence { get; private set; }
35
36 #region Overrides
37
38 public string SqlText { get { return ToString(); } }
39
40 #if OVERRIDETOSTRING
41
42 public override string ToString()
43 {
44 return ((IQueryElement)this).ToString(new StringBuilder(), new Dictionary<IQueryElement,IQueryElement>()).ToString();
45 }
46
47 #endif
48
49 #endregion
50
51 #region ISqlExpressionWalkable Members
52
53 [Obsolete]
54 ISqlExpression ISqlExpressionWalkable.Walk(bool skipColumns, Func<ISqlExpression,ISqlExpression> func)
55 {
56 Expr1 = Expr1.Walk(skipColumns, func);
57 Expr2 = Expr2.Walk(skipColumns, func);
58
59 return func(this);
60 }
61
62 #endregion
63
64 #region IEquatable<ISqlExpression> Members
65
66 bool IEquatable<ISqlExpression>.Equals(ISqlExpression other)
67 {
68 return Equals(other, SqlExpression.DefaultComparer);
69 }
70
71 #endregion
72
73 #region ISqlExpression Members
74
75 public bool CanBeNull()
76 {
77 return Expr1.CanBeNull() || Expr2.CanBeNull();
78 }
79
80 public bool Equals(ISqlExpression other, Func<ISqlExpression,ISqlExpression,bool> comparer)
81 {
82 if (this == other)
83 return true;
84
85 var expr = other as SqlBinaryExpression;
86
87 return
88 expr != null &&
89 Operation == expr.Operation &&
90 SystemType == expr.SystemType &&
91 Expr1.Equals(expr.Expr1, comparer) &&
92 Expr2.Equals(expr.Expr2, comparer) &&
93 comparer(this, other);
94 }
95
96 #endregion
97
98 #region ICloneableElement Members
99
100 public ICloneableElement Clone(Dictionary<ICloneableElement, ICloneableElement> objectTree, Predicate<ICloneableElement> doClone)
101 {
102 if (!doClone(this))
103 return this;
104
105 ICloneableElement clone;
106
107 if (!objectTree.TryGetValue(this, out clone))
108 {
109 objectTree.Add(this, clone = new SqlBinaryExpression(
110 SystemType,
111 (ISqlExpression)Expr1.Clone(objectTree, doClone),
112 Operation,
113 (ISqlExpression)Expr2.Clone(objectTree, doClone),
114 Precedence));
115 }
116
117 return clone;
118 }
119
120 #endregion
121
122 #region IQueryElement Members
123
124 public QueryElementType ElementType { get { return QueryElementType.SqlBinaryExpression; } }
125
126 StringBuilder IQueryElement.ToString(StringBuilder sb, Dictionary<IQueryElement,IQueryElement> dic)
127 {
128 Expr1
129 .ToString(sb, dic)
130 .Append(' ')
131 .Append(Operation)
132 .Append(' ');
133
134 return Expr2.ToString(sb, dic);
135 }
136
137 #endregion
138 }
139 }