forked from dynamicexpresso/DynamicExpresso
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParseSignatures.cs
More file actions
173 lines (160 loc) · 5.68 KB
/
ParseSignatures.cs
File metadata and controls
173 lines (160 loc) · 5.68 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DynamicExpresso.Reflection;
namespace DynamicExpresso.Parsing
{
/// <summary>
/// Contains all the signatures for the binary and unary operators supported by DynamicExpresso.
/// It allows to reuse the existing method resolutions logic in <see cref="Resolution.MethodResolution"/>.
/// </summary>
internal static class ParseSignatures
{
private static MethodBase[] MakeUnarySignatures(params Type[] possibleOperandTypes)
{
var signatures = new MethodBase[possibleOperandTypes.Length];
for (var i = 0; i < possibleOperandTypes.Length; i++)
{
signatures[i] = new SimpleMethodSignature(possibleOperandTypes[i]);
}
return signatures;
}
private static MethodBase[] MakeBinarySignatures(IList<(Type, Type)> possibleOperandTypes)
{
var signatures = new MethodBase[possibleOperandTypes.Count];
for (var i = 0; i < possibleOperandTypes.Count; i++)
{
var (left, right) = possibleOperandTypes[i];
signatures[i] = new SimpleMethodSignature(left, right);
}
return signatures;
}
/// <summary>
/// Signatures for the binary logical operators.
/// </summary>
public static MethodBase[] LogicalSignatures = MakeBinarySignatures(new[]
{
(typeof(bool), typeof(bool) ),
(typeof(bool?), typeof(bool?)),
});
/// <summary>
/// Signatures for the binary arithmetic operators.
/// </summary>
public static MethodBase[] ArithmeticSignatures = MakeBinarySignatures(new[]
{
(typeof(int), typeof(int) ),
(typeof(uint), typeof(uint) ),
(typeof(long), typeof(long) ),
(typeof(ulong), typeof(ulong) ),
(typeof(float), typeof(float) ),
(typeof(double), typeof(double) ),
(typeof(decimal), typeof(decimal) ),
(typeof(int?), typeof(int?) ),
(typeof(uint?), typeof(uint?) ),
(typeof(long?), typeof(long?) ),
(typeof(ulong?), typeof(ulong?) ),
(typeof(float?), typeof(float?) ),
(typeof(double?), typeof(double?) ),
(typeof(decimal?), typeof(decimal?)),
});
/// <summary>
/// Signatures for the binary relational operators.
/// </summary>
public static MethodBase[] RelationalSignatures = ArithmeticSignatures.Concat(MakeBinarySignatures(new[]
{
(typeof(string), typeof(string) ),
(typeof(char), typeof(char) ),
(typeof(DateTime), typeof(DateTime) ),
(typeof(TimeSpan), typeof(TimeSpan) ),
(typeof(char?), typeof(char?) ),
(typeof(DateTime?), typeof(DateTime?)),
(typeof(TimeSpan?), typeof(TimeSpan?)),
})).ToArray();
/// <summary>
/// Signatures for the binary equality operators.
/// </summary>
public static MethodBase[] EqualitySignatures = RelationalSignatures.Concat(LogicalSignatures).ToArray();
/// <summary>
/// Signatures for the binary + operators.
/// </summary>
public static MethodBase[] AddSignatures = ArithmeticSignatures.Concat(MakeBinarySignatures(new[]
{
(typeof(DateTime), typeof(TimeSpan) ),
(typeof(TimeSpan), typeof(TimeSpan) ),
(typeof(DateTime?), typeof(TimeSpan?)),
(typeof(TimeSpan?), typeof(TimeSpan?)),
})).ToArray();
/// <summary>
/// Signatures for the binary - operators.
/// </summary>
public static MethodBase[] SubtractSignatures = AddSignatures.Concat(MakeBinarySignatures(new[]
{
(typeof(DateTime), typeof(DateTime)),
(typeof(DateTime?), typeof(DateTime?)),
})).ToArray();
/// <summary>
/// Signatures for the unary - operators.
/// </summary>
public static MethodBase[] NegationSignatures = MakeUnarySignatures(
typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal),
typeof(int?), typeof(uint?), typeof(long?), typeof(ulong?), typeof(float?), typeof(double?), typeof(decimal?)
);
/// <summary>
/// Signatures for the unary not (!) operator.
/// </summary>
public static MethodBase[] NotSignatures = MakeUnarySignatures(typeof(bool), typeof(bool?));
/// <summary>
/// Signatures for the bitwise completement operators.
/// </summary>
public static MethodBase[] BitwiseComplementSignatures = MakeUnarySignatures(
typeof(int), typeof(uint), typeof(long), typeof(ulong),
typeof(int?), typeof(uint?), typeof(long?), typeof(ulong?)
);
/// <summary>
/// Signatures for the left and right shift operators.
/// </summary>
public static MethodBase[] ShiftSignatures = MakeBinarySignatures(new[]
{
(typeof(int), typeof(int) ),
(typeof(uint), typeof(int) ),
(typeof(long), typeof(int) ),
(typeof(ulong), typeof(int) ),
(typeof(int?), typeof(int?) ),
(typeof(uint?), typeof(int?) ),
(typeof(long?), typeof(int?) ),
(typeof(ulong?),typeof(int?) ),
});
//interface IEnumerableSignatures
//{
// void Where(bool predicate);
// void Any();
// void Any(bool predicate);
// void All(bool predicate);
// void Count();
// void Count(bool predicate);
// void Min(object selector);
// void Max(object selector);
// void Sum(int selector);
// void Sum(int? selector);
// void Sum(long selector);
// void Sum(long? selector);
// void Sum(float selector);
// void Sum(float? selector);
// void Sum(double selector);
// void Sum(double? selector);
// void Sum(decimal selector);
// void Sum(decimal? selector);
// void Average(int selector);
// void Average(int? selector);
// void Average(long selector);
// void Average(long? selector);
// void Average(float selector);
// void Average(float? selector);
// void Average(double selector);
// void Average(double? selector);
// void Average(decimal selector);
// void Average(decimal? selector);
//}
}
}