Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
197 lines (172 loc) · 8.13 KB

File metadata and controls

197 lines (172 loc) · 8.13 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System.Collections.Generic;
namespace Simple.Data
{
using System;
using System.Linq;
using Commands;
public class FunctionReference : SimpleReference, IEquatable<FunctionReference>
{
private static readonly HashSet<string> KnownFunctionNames = new HashSet<string>
{
"min", "max", "average", "length", "sum", "count",
};
private static readonly HashSet<string> AggregateFunctionNames = new HashSet<string>
{
"min", "max", "average", "sum", "count",
};
private readonly string _name;
private readonly SimpleReference _argument;
private readonly object[] _additionalArguments;
private readonly bool _isAggregate;
internal FunctionReference(string name, SimpleReference argument, params object[] additionalArguments)
{
_name = name;
_argument = argument;
_additionalArguments = additionalArguments;
_isAggregate = AggregateFunctionNames.Contains(name.ToLowerInvariant());
}
private FunctionReference(string name, SimpleReference argument, bool isAggregate, string alias, params object[] additionalArguments) : base(alias)
{
_name = name;
_argument = argument;
_isAggregate = isAggregate;
_additionalArguments = additionalArguments;
}
public IEnumerable<object> AdditionalArguments
{
get { return _additionalArguments.AsEnumerable(); }
}
public FunctionReference As(string alias)
{
return new FunctionReference(_name, _argument, _isAggregate, alias, _additionalArguments);
}
public override string GetAliasOrName()
{
return GetAlias() ?? _name + "_" + _argument.GetAliasOrName();
}
public bool IsAggregate
{
get { return _isAggregate; }
}
public string Name
{
get { return _name; }
}
public SimpleReference Argument
{
get { return _argument; }
}
public static bool TryCreate(string name, SimpleReference argument, out object functionReference)
{
if (!KnownFunctionNames.Contains(name.ToLowerInvariant()))
{
functionReference = null;
return false;
}
functionReference = new FunctionReference(name, argument);
return true;
}
/// <summary>
/// Implements the operator == to create a <see cref="SimpleExpression"/> with the type <see cref="SimpleExpressionType.Equal"/>.
/// </summary>
/// <param name="column">The column.</param>
/// <param name="value">The value.</param>
/// <returns>The expression.</returns>
public static SimpleExpression operator ==(FunctionReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.Equal);
}
/// <summary>
/// Implements the operator != to create a <see cref="SimpleExpression"/> with the type <see cref="SimpleExpressionType.NotEqual"/>.
/// </summary>
/// <param name="column">The column.</param>
/// <param name="value">The value.</param>
/// <returns>The expression.</returns>
public static SimpleExpression operator !=(FunctionReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.NotEqual);
}
/// <summary>
/// Implements the operator &lt; to create a <see cref="SimpleExpression"/> with the type <see cref="SimpleExpressionType.LessThan"/>.
/// </summary>
/// <param name="column">The column.</param>
/// <param name="value">The value.</param>
/// <returns>The expression.</returns>
public static SimpleExpression operator <(FunctionReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.LessThan);
}
/// <summary>
/// Implements the operator &gt; to create a <see cref="SimpleExpression"/> with the type <see cref="SimpleExpressionType.GreaterThan"/>.
/// </summary>
/// <param name="column">The column.</param>
/// <param name="value">The value.</param>
/// <returns>The expression.</returns>
public static SimpleExpression operator >(FunctionReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.GreaterThan);
}
/// <summary>
/// Implements the operator &lt;= to create a <see cref="SimpleExpression"/> with the type <see cref="SimpleExpressionType.LessThanOrEqual"/>.
/// </summary>
/// <param name="column">The column.</param>
/// <param name="value">The value.</param>
/// <returns>The expression.</returns>
public static SimpleExpression operator <=(FunctionReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.LessThanOrEqual);
}
/// <summary>
/// Implements the operator &gt;= to create a <see cref="SimpleExpression"/> with the type <see cref="SimpleExpressionType.GreaterThanOrEqual"/>.
/// </summary>
/// <param name="column">The column.</param>
/// <param name="value">The value.</param>
/// <returns>The expression.</returns>
public static SimpleExpression operator >=(FunctionReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.GreaterThanOrEqual);
}
public bool Equals(FunctionReference other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other._name, _name) && Equals(other._argument, _argument) && other._isAggregate.Equals(_isAggregate) && Equals(other.GetAlias(), GetAlias());
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (FunctionReference)) return false;
return Equals((FunctionReference) obj);
}
public override int GetHashCode()
{
unchecked
{
int result = (_name != null ? _name.GetHashCode() : 0);
result = (result*397) ^ (_argument != null ? _argument.GetHashCode() : 0);
result = (result*397) ^ _isAggregate.GetHashCode();
result = (result*397) ^ (GetAlias() != null ? GetAlias().GetHashCode() : 0);
return result;
}
}
public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
{
if (base.TryInvokeMember(binder, args, out result)) return true;
var dataStrategy = _argument.FindDataStrategyInHierarchy();
if (dataStrategy != null)
{
if (dataStrategy.IsExpressionFunction(binder.Name, args))
{
result = new SimpleExpression(this, new SimpleFunction(binder.Name, args), SimpleExpressionType.Function);
}
else
{
result = new FunctionReference(binder.Name, this, args);
}
return true;
}
return false;
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.