1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Diagnostics.CodeAnalysis;
5 
6 namespace System.Data.Linq.SqlClient {
7     internal static class SqlNodeTypeOperators {
8 
9         /// <summary>
10         /// Determines whether the given unary operator node type returns a value that
11         /// is predicate.
12         /// </summary>
13         [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification="These issues are related to our use of if-then and case statements for node types, which adds to the complexity count however when reviewed they are easy to navigate and understand.")]
IsPredicateUnaryOperator(this SqlNodeType nodeType)14         internal static bool IsPredicateUnaryOperator(this SqlNodeType nodeType) {
15             switch (nodeType) {
16                 case SqlNodeType.Not:
17                 case SqlNodeType.Not2V:
18                 case SqlNodeType.IsNull:
19                 case SqlNodeType.IsNotNull:
20                     return true;
21                 case SqlNodeType.Negate:
22                 case SqlNodeType.BitNot:
23                 case SqlNodeType.Count:
24                 case SqlNodeType.LongCount:
25                 case SqlNodeType.Max:
26                 case SqlNodeType.Min:
27                 case SqlNodeType.Sum:
28                 case SqlNodeType.Avg:
29                 case SqlNodeType.Stddev:
30                 case SqlNodeType.Convert:
31                 case SqlNodeType.ValueOf:
32                 case SqlNodeType.OuterJoinedValue:
33                 case SqlNodeType.ClrLength:
34                     return false;
35                 default:
36                     throw Error.UnexpectedNode(nodeType);
37             }
38         }
39 
40         /// <summary>
41         /// Determines whether the given unary operator expects a predicate as input.
42         /// </summary>
43         [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification="These issues are related to our use of if-then and case statements for node types, which adds to the complexity count however when reviewed they are easy to navigate and understand.")]
IsUnaryOperatorExpectingPredicateOperand(this SqlNodeType nodeType)44         internal static bool IsUnaryOperatorExpectingPredicateOperand(this SqlNodeType nodeType) {
45             switch (nodeType) {
46                 case SqlNodeType.Not:
47                 case SqlNodeType.Not2V:
48                     return true;
49                 case SqlNodeType.IsNull:
50                 case SqlNodeType.IsNotNull:
51                 case SqlNodeType.Negate:
52                 case SqlNodeType.BitNot:
53                 case SqlNodeType.Count:
54                 case SqlNodeType.LongCount:
55                 case SqlNodeType.Max:
56                 case SqlNodeType.Min:
57                 case SqlNodeType.Sum:
58                 case SqlNodeType.Avg:
59                 case SqlNodeType.Stddev:
60                 case SqlNodeType.Convert:
61                 case SqlNodeType.ValueOf:
62                 case SqlNodeType.OuterJoinedValue:
63                 case SqlNodeType.ClrLength:
64                     return false;
65                 default:
66                     throw Error.UnexpectedNode(nodeType);
67             }
68         }
69 
70         /// <summary>
71         /// Determines whether the given binary operator node type returns a value that
72         /// is a predicate boolean.
73         /// </summary>
74         [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification="These issues are related to our use of if-then and case statements for node types, which adds to the complexity count however when reviewed they are easy to navigate and understand.")]
IsPredicateBinaryOperator(this SqlNodeType nodeType)75         internal static bool IsPredicateBinaryOperator(this SqlNodeType nodeType) {
76             switch (nodeType) {
77                 case SqlNodeType.GE:
78                 case SqlNodeType.GT:
79                 case SqlNodeType.LE:
80                 case SqlNodeType.LT:
81                 case SqlNodeType.EQ:
82                 case SqlNodeType.NE:
83                 case SqlNodeType.EQ2V:
84                 case SqlNodeType.NE2V:
85                 case SqlNodeType.And:
86                 case SqlNodeType.Or:
87                     return true;
88                 case SqlNodeType.Add:
89                 case SqlNodeType.Sub:
90                 case SqlNodeType.Mul:
91                 case SqlNodeType.Div:
92                 case SqlNodeType.Mod:
93                 case SqlNodeType.BitAnd:
94                 case SqlNodeType.BitOr:
95                 case SqlNodeType.BitXor:
96                 case SqlNodeType.Concat:
97                 case SqlNodeType.Coalesce:
98                     return false;
99                 default:
100                     throw Error.UnexpectedNode(nodeType);
101             }
102         }
103         /// <summary>
104         /// Determines whether this operator is a binary comparison operator (i.e. >, =>, ==, etc)
105         /// </summary>
106         [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "These issues are related to our use of if-then and case statements for node types, which adds to the complexity count however when reviewed they are easy to navigate and understand.")]
IsComparisonOperator(this SqlNodeType nodeType)107         internal static bool IsComparisonOperator(this SqlNodeType nodeType)
108         {
109             switch (nodeType)
110             {
111                 case SqlNodeType.GE:
112                 case SqlNodeType.GT:
113                 case SqlNodeType.LE:
114                 case SqlNodeType.LT:
115                 case SqlNodeType.EQ:
116                 case SqlNodeType.NE:
117                 case SqlNodeType.EQ2V:
118                 case SqlNodeType.NE2V:
119                     return true;
120                 case SqlNodeType.And:
121                 case SqlNodeType.Or:
122                 case SqlNodeType.Add:
123                 case SqlNodeType.Sub:
124                 case SqlNodeType.Mul:
125                 case SqlNodeType.Div:
126                 case SqlNodeType.Mod:
127                 case SqlNodeType.BitAnd:
128                 case SqlNodeType.BitOr:
129                 case SqlNodeType.BitXor:
130                 case SqlNodeType.Concat:
131                 case SqlNodeType.Coalesce:
132                     return false;
133                 default:
134                     throw Error.UnexpectedNode(nodeType);
135             }
136         }
137 
138         /// <summary>
139         /// Determines whether the given binary operator node type returns a value that
140         /// is a predicate boolean.
141         /// </summary>
142         [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification="These issues are related to our use of if-then and case statements for node types, which adds to the complexity count however when reviewed they are easy to navigate and understand.")]
IsBinaryOperatorExpectingPredicateOperands(this SqlNodeType nodeType)143         internal static bool IsBinaryOperatorExpectingPredicateOperands(this SqlNodeType nodeType) {
144             switch (nodeType) {
145                 case SqlNodeType.And:
146                 case SqlNodeType.Or:
147                     return true;
148                 case SqlNodeType.EQ:
149                 case SqlNodeType.EQ2V:
150                 case SqlNodeType.GE:
151                 case SqlNodeType.GT:
152                 case SqlNodeType.LE:
153                 case SqlNodeType.LT:
154                 case SqlNodeType.NE:
155                 case SqlNodeType.NE2V:
156                 case SqlNodeType.Add:
157                 case SqlNodeType.Sub:
158                 case SqlNodeType.Mul:
159                 case SqlNodeType.Div:
160                 case SqlNodeType.Mod:
161                 case SqlNodeType.BitAnd:
162                 case SqlNodeType.BitOr:
163                 case SqlNodeType.BitXor:
164                 case SqlNodeType.Concat:
165                 case SqlNodeType.Coalesce:
166                     return false;
167                 default:
168                     throw Error.UnexpectedNode(nodeType);
169             }
170         }
171 
172         /// <summary>
173         /// Determines whether the given node requires support on the client for evaluation.
174         /// For example, LINK nodes may be delay-executed only when the user requests the result.
175         /// </summary>
IsClientAidedExpression(this SqlExpression expr)176         internal static bool IsClientAidedExpression(this SqlExpression expr) {
177             switch (expr.NodeType) {
178                 case SqlNodeType.Link:
179                 case SqlNodeType.Element:
180                 case SqlNodeType.Multiset:
181                 case SqlNodeType.ClientQuery:
182                 case SqlNodeType.TypeCase:
183                 case SqlNodeType.New:
184                     return true;
185                 default:
186                     return false;
187             };
188         }
189     }
190 }
191