|
1 | 1 | using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using DynamicExpresso.Reflection; |
2 | 5 |
|
3 | 6 | namespace DynamicExpresso.Parsing |
4 | 7 | { |
5 | 8 | internal class ParseSignatures |
6 | 9 | { |
7 | | - public interface ILogicalSignatures |
| 10 | + private static MethodData[] MakeUnarySignatures(params Type[] possibleParamTypes) |
8 | 11 | { |
9 | | - void F(bool x, bool y); |
10 | | - void F(bool? x, bool? y); |
| 12 | + var signatures = new MethodData[possibleParamTypes.Length]; |
| 13 | + for (var i = 0; i < possibleParamTypes.Length; i++) |
| 14 | + { |
| 15 | + signatures[i] = new MethodData |
| 16 | + { |
| 17 | + Parameters = new[] { new SimpleParameterInfo(possibleParamTypes[i]) }, |
| 18 | + }; |
| 19 | + } |
| 20 | + return signatures; |
11 | 21 | } |
12 | 22 |
|
13 | | - public interface IArithmeticSignatures |
| 23 | + private static MethodData[] MakeBinarySignatures(IList<(Type, Type)> possibleParamTypes) |
14 | 24 | { |
15 | | - void F(int x, int y); |
16 | | - void F(uint x, uint y); |
17 | | - void F(long x, long y); |
18 | | - void F(ulong x, ulong y); |
19 | | - void F(float x, float y); |
20 | | - void F(double x, double y); |
21 | | - void F(decimal x, decimal y); |
22 | | - void F(int? x, int? y); |
23 | | - void F(uint? x, uint? y); |
24 | | - void F(long? x, long? y); |
25 | | - void F(ulong? x, ulong? y); |
26 | | - void F(float? x, float? y); |
27 | | - void F(double? x, double? y); |
28 | | - void F(decimal? x, decimal? y); |
| 25 | + var signatures = new MethodData[possibleParamTypes.Count]; |
| 26 | + for (var i = 0; i < possibleParamTypes.Count; i++) |
| 27 | + { |
| 28 | + var (left, right) = possibleParamTypes[i]; |
| 29 | + signatures[i] = new MethodData |
| 30 | + { |
| 31 | + Parameters = new[] { new SimpleParameterInfo(left), new SimpleParameterInfo(right) }, |
| 32 | + }; |
| 33 | + } |
| 34 | + return signatures; |
29 | 35 | } |
30 | 36 |
|
31 | | - public interface IRelationalSignatures : IArithmeticSignatures |
| 37 | + /// <summary> |
| 38 | + /// Signatures for the binary logical operators. |
| 39 | + /// </summary> |
| 40 | + public static MethodData[] LogicalSignatures = MakeBinarySignatures(new[] |
32 | 41 | { |
33 | | - void F(string x, string y); |
34 | | - void F(char x, char y); |
35 | | - void F(DateTime x, DateTime y); |
36 | | - void F(TimeSpan x, TimeSpan y); |
37 | | - void F(char? x, char? y); |
38 | | - void F(DateTime? x, DateTime? y); |
39 | | - void F(TimeSpan? x, TimeSpan? y); |
40 | | - } |
| 42 | + (typeof(bool), typeof(bool) ), |
| 43 | + (typeof(bool?), typeof(bool?)), |
| 44 | + }); |
41 | 45 |
|
42 | | - public interface IEqualitySignatures : IRelationalSignatures |
| 46 | + /// <summary> |
| 47 | + /// Signatures for the binary arithmetic operators. |
| 48 | + /// </summary> |
| 49 | + public static MethodData[] ArithmeticSignatures = MakeBinarySignatures(new[] |
43 | 50 | { |
44 | | - void F(bool x, bool y); |
45 | | - void F(bool? x, bool? y); |
46 | | - } |
| 51 | + (typeof(int), typeof(int) ), |
| 52 | + (typeof(uint), typeof(uint) ), |
| 53 | + (typeof(long), typeof(long) ), |
| 54 | + (typeof(ulong), typeof(ulong) ), |
| 55 | + (typeof(float), typeof(float) ), |
| 56 | + (typeof(double), typeof(double) ), |
| 57 | + (typeof(decimal), typeof(decimal) ), |
| 58 | + (typeof(int?), typeof(int?) ), |
| 59 | + (typeof(uint?), typeof(uint?) ), |
| 60 | + (typeof(long?), typeof(long?) ), |
| 61 | + (typeof(ulong?), typeof(ulong?) ), |
| 62 | + (typeof(float?), typeof(float?) ), |
| 63 | + (typeof(double?), typeof(double?) ), |
| 64 | + (typeof(decimal?), typeof(decimal?)), |
| 65 | + }); |
47 | 66 |
|
48 | | - public interface IAddSignatures : IArithmeticSignatures |
| 67 | + /// <summary> |
| 68 | + /// Signatures for the binary relational operators. |
| 69 | + /// </summary> |
| 70 | + public static MethodData[] RelationalSignatures = ArithmeticSignatures.Concat(MakeBinarySignatures(new[] |
49 | 71 | { |
50 | | - void F(DateTime x, TimeSpan y); |
51 | | - void F(TimeSpan x, TimeSpan y); |
52 | | - void F(DateTime? x, TimeSpan? y); |
53 | | - void F(TimeSpan? x, TimeSpan? y); |
54 | | - } |
| 72 | + (typeof(string), typeof(string) ), |
| 73 | + (typeof(char), typeof(char) ), |
| 74 | + (typeof(DateTime), typeof(DateTime) ), |
| 75 | + (typeof(TimeSpan), typeof(TimeSpan) ), |
| 76 | + (typeof(char?), typeof(char?) ), |
| 77 | + (typeof(DateTime?), typeof(DateTime?)), |
| 78 | + (typeof(TimeSpan?), typeof(TimeSpan?)), |
| 79 | + })).ToArray(); |
55 | 80 |
|
56 | | - public interface ISubtractSignatures : IAddSignatures |
57 | | - { |
58 | | - void F(DateTime x, DateTime y); |
59 | | - void F(DateTime? x, DateTime? y); |
60 | | - } |
| 81 | + /// <summary> |
| 82 | + /// Signatures for the binary equality operators. |
| 83 | + /// </summary> |
| 84 | + public static MethodData[] EqualitySignatures = RelationalSignatures.Concat(LogicalSignatures).ToArray(); |
61 | 85 |
|
62 | | - public interface INegationSignatures |
| 86 | + /// <summary> |
| 87 | + /// Signatures for the binary + operators. |
| 88 | + /// </summary> |
| 89 | + public static MethodData[] AddSignatures = ArithmeticSignatures.Concat(MakeBinarySignatures(new[] |
63 | 90 | { |
64 | | - void F(int x); |
65 | | - void F(long x); |
66 | | - void F(float x); |
67 | | - void F(double x); |
68 | | - void F(decimal x); |
69 | | - void F(int? x); |
70 | | - void F(long? x); |
71 | | - void F(float? x); |
72 | | - void F(double? x); |
73 | | - void F(decimal? x); |
74 | | - } |
| 91 | + (typeof(DateTime), typeof(TimeSpan) ), |
| 92 | + (typeof(TimeSpan), typeof(TimeSpan) ), |
| 93 | + (typeof(DateTime?), typeof(TimeSpan?)), |
| 94 | + (typeof(TimeSpan?), typeof(TimeSpan?)), |
| 95 | + })).ToArray(); |
75 | 96 |
|
76 | | - public interface INotSignatures |
| 97 | + /// <summary> |
| 98 | + /// Signatures for the binary - operators. |
| 99 | + /// </summary> |
| 100 | + public static MethodData[] SubtractSignatures = AddSignatures.Concat(MakeBinarySignatures(new[] |
77 | 101 | { |
78 | | - void F(bool x); |
79 | | - void F(bool? x); |
80 | | - } |
| 102 | + (typeof(DateTime), typeof(DateTime)), |
| 103 | + (typeof(DateTime?), typeof(DateTime?)), |
| 104 | + })).ToArray(); |
81 | 105 |
|
82 | | - public interface IBitwiseComplementSignatures |
83 | | - { |
84 | | - void F(int x, int count); |
85 | | - void F(uint x, int count); |
86 | | - void F(long x, int count); |
87 | | - void F(ulong x, int count); |
88 | | - void F(int? x, int? count); |
89 | | - void F(uint? x, int? count); |
90 | | - void F(long? x, int? count); |
91 | | - void F(ulong? x, int? count); |
92 | | - } |
| 106 | + /// <summary> |
| 107 | + /// Signatures for the unary - operators. |
| 108 | + /// </summary> |
| 109 | + public static MethodData[] NegationSignatures = MakeUnarySignatures( |
| 110 | + typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal), |
| 111 | + typeof(int?), typeof(uint?), typeof(long?), typeof(ulong?), typeof(float?), typeof(double?), typeof(decimal?) |
| 112 | + ); |
93 | 113 |
|
94 | | - // the signatures are the same for the left and right shifts |
95 | | - public interface IShiftSignatures |
| 114 | + /// <summary> |
| 115 | + /// Signatures for the unary not (!) operator. |
| 116 | + /// </summary> |
| 117 | + public static MethodData[] NotSignatures = MakeUnarySignatures(typeof(bool), typeof(bool?)); |
| 118 | + |
| 119 | + /// <summary> |
| 120 | + /// Signatures for the bitwise completement operators. |
| 121 | + /// </summary> |
| 122 | + public static MethodData[] BitwiseComplementSignatures = MakeUnarySignatures( |
| 123 | + typeof(int), typeof(uint), typeof(long), typeof(ulong), |
| 124 | + typeof(int?), typeof(uint?), typeof(long?), typeof(ulong?) |
| 125 | + ); |
| 126 | + |
| 127 | + /// <summary> |
| 128 | + /// Signatures for the left and right shift operators. |
| 129 | + /// </summary> |
| 130 | + public static MethodData[] ShiftSignatures = MakeBinarySignatures(new[] |
96 | 131 | { |
97 | | - void F(int x); |
98 | | - void F(uint x); |
99 | | - void F(long x); |
100 | | - void F(ulong x); |
101 | | - void F(int? x); |
102 | | - void F(uint? x); |
103 | | - void F(long? x); |
104 | | - void F(ulong? x); |
105 | | - } |
| 132 | + (typeof(int), typeof(int) ), |
| 133 | + (typeof(uint), typeof(int) ), |
| 134 | + (typeof(long), typeof(int) ), |
| 135 | + (typeof(ulong), typeof(int) ), |
| 136 | + (typeof(int?), typeof(int?) ), |
| 137 | + (typeof(uint?), typeof(int?) ), |
| 138 | + (typeof(long?), typeof(int?) ), |
| 139 | + (typeof(ulong?),typeof(int?) ), |
| 140 | + }); |
106 | 141 |
|
107 | 142 | //interface IEnumerableSignatures |
108 | 143 | //{ |
|
0 commit comments