-
Notifications
You must be signed in to change notification settings - Fork 0
/
BooleanExtension.cs
185 lines (142 loc) · 6.31 KB
/
BooleanExtension.cs
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
using System;
namespace Aya.Extension
{
public static partial class BooleanExtensions
{
#region Convert
public static string ToYesNoString(this bool boolean)
{
var result = boolean ? "Yes" : "No";
return result;
}
public static int ToBinaryNumber(this bool boolean)
{
var result = boolean ? 1 : 0;
return result;
}
#endregion
#region Logic
// https://github.com/TeodorVecerdi/UnityCommons/blob/main/Runtime/Code/Extensions/BooleanExtensions.cs
#region And
public static bool And(this bool boolean, bool other)
{
return boolean && other;
}
public static bool And(this bool boolean, Func<bool> other)
{
return other != null && boolean && other();
}
public static bool And<T>(this bool boolean, Func<T, bool> other, T value)
{
return other != null && boolean && other(value);
}
public static bool And<T1, T2>(this bool boolean, Func<T1, T2, bool> other, T1 value1, T2 value2)
{
return other != null && boolean && other(value1, value2);
}
public static bool And<T1, T2, T3>(this bool boolean, Func<T1, T2, T3, bool> other, T1 value1, T2 value2, T3 value3)
{
return other != null && boolean && other(value1, value2, value3);
}
public static bool And<T1, T2, T3, T4>(this bool boolean, Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)
{
return other != null && boolean && other(value1, value2, value3, value4);
}
public static bool And<T1, T2, T3, T4, T5>(this bool boolean, Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)
{
return other != null && boolean && other(value1, value2, value3, value4, value5);
}
#endregion
#region Or
public static bool Or(this bool boolean, bool other)
{
return boolean || other;
}
public static bool Or(this bool boolean, Func<bool> other)
{
return other == null ? boolean : boolean || other();
}
public static bool Or<T>(this bool boolean, Func<T, bool> other, T value)
{
return other == null ? boolean : boolean || other(value);
}
public static bool Or<T1, T2>(this bool boolean, Func<T1, T2, bool> other, T1 value1, T2 value2)
{
return other == null ? boolean : boolean || other(value1, value2);
}
public static bool Or<T1, T2, T3>(this bool boolean, Func<T1, T2, T3, bool> other, T1 value1, T2 value2, T3 value3)
{
return other == null ? boolean : boolean || other(value1, value2, value3);
}
public static bool Or<T1, T2, T3, T4>(this bool boolean, Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)
{
return other == null ? boolean : boolean || other(value1, value2, value3, value4);
}
public static bool Or<T1, T2, T3, T4, T5>(this bool boolean, Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)
{
return other == null ? boolean : boolean || other(value1, value2, value3, value4, value5);
}
#endregion
#region AndNot
public static bool AndNot(this bool boolean, bool other)
{
return boolean && !other;
}
public static bool AndNot(this bool boolean, Func<bool> other)
{
return other != null && boolean && !other();
}
public static bool AndNot<T>(this bool boolean, Func<T, bool> other, T value)
{
return other != null && boolean && !other(value);
}
public static bool AndNot<T1, T2>(this bool boolean, Func<T1, T2, bool> other, T1 value1, T2 value2)
{
return other != null && boolean && !other(value1, value2);
}
public static bool AndNot<T1, T2, T3>(this bool boolean, Func<T1, T2, T3, bool> other, T1 value1, T2 value2, T3 value3)
{
return other != null && boolean && !other(value1, value2, value3);
}
public static bool AndNot<T1, T2, T3, T4>(this bool boolean, Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)
{
return other != null && boolean && !other(value1, value2, value3, value4);
}
public static bool AndNot<T1, T2, T3, T4, T5>(this bool boolean, Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)
{
return other != null && boolean && !other(value1, value2, value3, value4, value5);
}
#endregion
#region OrNot
public static bool OrNot(this bool boolean, bool other)
{
return boolean || !other;
}
public static bool OrNot(this bool boolean, Func<bool> other)
{
return other == null ? boolean : boolean || !other();
}
public static bool OrNot<T>(this bool boolean, Func<T, bool> other, T value)
{
return other == null ? boolean : boolean || !other(value);
}
public static bool OrNot<T1, T2>(this bool boolean, Func<T1, T2, bool> other, T1 value1, T2 value2)
{
return other == null ? boolean : boolean || !other(value1, value2);
}
public static bool OrNot<T1, T2, T3>(this bool boolean, Func<T1, T2, T3, bool> other, T1 value1, T2 value2, T3 value3)
{
return other == null ? boolean : boolean || !other(value1, value2, value3);
}
public static bool OrNot<T1, T2, T3, T4>(this bool boolean, Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)
{
return other == null ? boolean : boolean || !other(value1, value2, value3, value4);
}
public static bool OrNot<T1, T2, T3, T4, T5>(this bool boolean, Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)
{
return other == null ? boolean : boolean || !other(value1, value2, value3, value4, value5);
}
#endregion
#endregion
}
}