forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathReference.cs
More file actions
137 lines (122 loc) · 5.26 KB
/
MathReference.cs
File metadata and controls
137 lines (122 loc) · 5.26 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Simple.Data
{
public class MathReference : SimpleReference, IEquatable<MathReference>
{
private readonly object _leftOperand;
private readonly object _rightOperand;
private readonly MathOperator _operator;
public MathReference(object leftOperand, object rightOperand, MathOperator @operator)
{
_leftOperand = leftOperand;
_rightOperand = rightOperand;
_operator = @operator;
}
public MathOperator Operator
{
get { return _operator; }
}
public object RightOperand
{
get { return _rightOperand; }
}
public object LeftOperand
{
get { return _leftOperand; }
}
/// <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 ==(MathReference 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 !=(MathReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.NotEqual);
}
/// <summary>
/// Implements the operator < 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 <(MathReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.LessThan);
}
/// <summary>
/// Implements the operator > 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 >(MathReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.GreaterThan);
}
/// <summary>
/// Implements the operator <= 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 <=(MathReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.LessThanOrEqual);
}
/// <summary>
/// Implements the operator >= 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 >=(MathReference column, object value)
{
return new SimpleExpression(column, value, SimpleExpressionType.GreaterThanOrEqual);
}
public bool Equals(MathReference other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other._leftOperand, _leftOperand) && Equals(other._rightOperand, _rightOperand) && Equals(other._operator, _operator);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (MathReference)) return false;
return Equals((MathReference) obj);
}
public override int GetHashCode()
{
unchecked
{
int result = (_leftOperand != null ? _leftOperand.GetHashCode() : 0);
result = (result*397) ^ (_rightOperand != null ? _rightOperand.GetHashCode() : 0);
result = (result*397) ^ _operator.GetHashCode();
return result;
}
}
}
public enum MathOperator
{
Add,
Subtract,
Multiply,
Divide,
Modulo
}
}