5 // Chris J Breisch (cjbreisch@altavista.net)
6 // Francesco Delfino (pluto@tipic.com)
8 // (C) 2002 Chris J Breisch
9 // 2002 Tipic, Inc (http://www.tipic.com)
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 //namespace Microsoft.VisualBasic.CompilerServices {
38 // [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
39 // sealed public class ObjectType {
42 // public static System.Int32 ObjTst (System.Object o1, System.Object o2, System.Boolean TextCompare) { throw new NotImplementedException (); }
44 // public static System.Object PlusObj (System.Object obj) { throw new NotImplementedException (); }
46 // public static System.Object NegObj (System.Object obj) { throw new NotImplementedException (); }
48 // public static System.Object NotObj (System.Object obj) { throw new NotImplementedException (); }
50 // public static System.Object BitAndObj (System.Object obj1, System.Object obj2) { throw new NotImplementedException (); }
52 // public static System.Object BitOrObj (System.Object obj1, System.Object obj2) { throw new NotImplementedException (); }
54 // public static System.Object BitXorObj (System.Object obj1, System.Object obj2) { throw new NotImplementedException (); }
56 // public static System.Object AddObj (System.Object o1, System.Object o2) { throw new NotImplementedException (); }
58 // public static System.Object SubObj (System.Object o1, System.Object o2) { throw new NotImplementedException (); }
60 // public static System.Object MulObj (System.Object o1, System.Object o2) { throw new NotImplementedException (); }
62 // public static System.Object DivObj (System.Object o1, System.Object o2) { throw new NotImplementedException (); }
64 // public static System.Object PowObj (System.Object obj1, System.Object obj2) { throw new NotImplementedException (); }
66 // public static System.Object ModObj (System.Object o1, System.Object o2) { throw new NotImplementedException (); }
68 // public static System.Object IDivObj (System.Object o1, System.Object o2) { throw new NotImplementedException (); }
70 // public static System.Object XorObj (System.Object obj1, System.Object obj2) { throw new NotImplementedException (); }
72 // public static System.Boolean LikeObj (System.Object vLeft, System.Object vRight, Microsoft.VisualBasic.CompareMethod CompareOption) { throw new NotImplementedException (); }
74 // public static System.Object StrCatObj (System.Object vLeft, System.Object vRight) { throw new NotImplementedException (); }
76 // public static System.Object GetObjectValuePrimitive (System.Object o) { throw new NotImplementedException (); }
85 // Chris J Breisch (cjbreisch@altavista.net)
86 // Francesco Delfino (pluto@tipic.com)
88 // (C) 2002 Chris J Breisch
89 // 2002 Tipic, Inc (http://www.tipic.com)
93 * Copyright (c) 2002-2003 Mainsoft Corporation.
95 * Permission is hereby granted, free of charge, to any person obtaining a
96 * copy of this software and associated documentation files (the "Software"),
97 * to deal in the Software without restriction, including without limitation
98 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
99 * and/or sell copies of the Software, and to permit persons to whom the
100 * Software is furnished to do so, subject to the following conditions:
102 * The above copyright notice and this permission notice shall be included in
103 * all copies or substantial portions of the Software.
105 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
110 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
111 * DEALINGS IN THE SOFTWARE.
115 using System
.Collections
;
116 using Microsoft
.VisualBasic
;
117 namespace Microsoft
.VisualBasic
.CompilerServices
{
118 [System
.ComponentModel
.EditorBrowsableAttribute(System
.ComponentModel
.EditorBrowsableState
.Never
)]
119 sealed public class ObjectType
{
121 private static int[,] ConversionClassTable
= new int[13,13];
122 private static Type
[,] WiderType
= new Type
[12,12];
123 private static int [] VType2FromTypeCode
= new int[19];
124 private static Type
[] tblTypeFromTypeCode
= new Type
[19];//added tbl prefix to differencate field from method
125 private static int [] VTypeFromTypeCode
= new int[19];
126 private static int [] TypeCodeFromVType
= new int[13];
129 // WiderType[VType.t_bad][VType.t_bad] = VType.t_bad;
130 // WiderType[VType.t_bad][VType.t_bool] = VType.t_bad;
131 // WiderType[VType.t_bad][VType.t_ui1] = VType.t_bad;
132 // WiderType[VType.t_bad][VType.t_i2] = VType.t_bad;
133 // WiderType[VType.t_bad][VType.t_i4] = VType.t_bad;
134 // WiderType[VType.t_bad][VType.t_i8] = VType.t_bad;
135 // WiderType[VType.t_bad][VType.t_dec] = VType.t_bad;
136 // WiderType[VType.t_bad][VType.t_r4] = VType.t_bad;
137 // WiderType[VType.t_bad][VType.t_r8] = VType.t_bad;
138 // WiderType[VType.t_bad][VType.t_char] = VType.t_bad;
139 // WiderType[VType.t_bad][VType.t_str] = VType.t_bad;
140 // WiderType[VType.t_bad][VType.t_date] = VType.t_bad;
142 // WiderType[VType.t_bool][VType.t_bad] = VType.t_bad;
143 // WiderType[VType.t_bool][VType.t_bool] = VType.t_bool;
144 // WiderType[VType.t_bool][VType.t_ui1] = VType.t_bool;
145 // WiderType[VType.t_bool][VType.t_i2] = VType.t_i2;
146 // WiderType[VType.t_bool][VType.t_i4] = VType.t_i4;
147 // WiderType[VType.t_bool][VType.t_i8] = VType.t_i8;
148 // WiderType[VType.t_bool][VType.t_dec] = VType.t_dec;
149 // WiderType[VType.t_bool][VType.t_r4] = VType.t_r4;
150 // WiderType[VType.t_bool][VType.t_r8] = VType.t_r8;
151 // WiderType[VType.t_bool][VType.t_char] = VType.t_bad;
152 // WiderType[VType.t_bool][VType.t_str] = VType.t_r8;
153 // WiderType[VType.t_bool][VType.t_date] = VType.t_bad;
155 // WiderType[VType.t_ui1][VType.t_bad] = VType.t_bad;
156 // WiderType[VType.t_ui1][VType.t_bool] = VType.t_bool;
157 // WiderType[VType.t_ui1][VType.t_ui1] = VType.t_ui1;
158 // WiderType[VType.t_ui1][VType.t_i2] = VType.t_i2;
159 // WiderType[VType.t_ui1][VType.t_i4] = VType.t_i4;
160 // WiderType[VType.t_ui1][VType.t_i8] = VType.t_i8;
161 // WiderType[VType.t_ui1][VType.t_dec] = VType.t_dec;
162 // WiderType[VType.t_ui1][VType.t_r4] = VType.t_r4;
163 // WiderType[VType.t_ui1][VType.t_r8] = VType.t_r8;
164 // WiderType[VType.t_ui1][VType.t_char] = VType.t_bad;
165 // WiderType[VType.t_ui1][VType.t_str] = VType.t_r8;
166 // WiderType[VType.t_ui1][VType.t_date] = VType.t_bad;
168 // WiderType[VType.t_i2][VType.t_bad] = VType.t_bad;
169 // WiderType[VType.t_i2][VType.t_bool] = VType.t_i2;
170 // WiderType[VType.t_i2][VType.t_ui1] = VType.t_i2;
171 // WiderType[VType.t_i2][VType.t_i2] = VType.t_i2;
172 // WiderType[VType.t_i2][VType.t_i4] = VType.t_i4;
173 // WiderType[VType.t_i2][VType.t_i8] = VType.t_i8;
174 // WiderType[VType.t_i2][VType.t_dec] = VType.t_dec;
175 // WiderType[VType.t_i2][VType.t_r4] = VType.t_r4;
176 // WiderType[VType.t_i2][VType.t_r8] = VType.t_r8;
177 // WiderType[VType.t_i2][VType.t_char] = VType.t_bad;
178 // WiderType[VType.t_i2][VType.t_str] = VType.t_r8;
179 // WiderType[VType.t_i2][VType.t_date] = VType.t_bad;
181 // WiderType[VType.t_i4][VType.t_bad] = VType.t_bad;
182 // WiderType[VType.t_i4][VType.t_bool] = VType.t_i4;
183 // WiderType[VType.t_i4][VType.t_ui1] = VType.t_i4;
184 // WiderType[VType.t_i4][VType.t_i2] = VType.t_i4;
185 // WiderType[VType.t_i4][VType.t_i4] = VType.t_i4;
186 // WiderType[VType.t_i4][VType.t_i8] = VType.t_i8;
187 // WiderType[VType.t_i4][VType.t_dec] = VType.t_dec;
188 // WiderType[VType.t_i4][VType.t_r4] = VType.t_r4;
189 // WiderType[VType.t_i4][VType.t_r8] = VType.t_r8;
190 // WiderType[VType.t_i4][VType.t_char] = VType.t_bad;
191 // WiderType[VType.t_i4][VType.t_str] = VType.t_r8;
192 // WiderType[VType.t_i4][VType.t_date] = VType.t_bad;
194 // WiderType[VType.t_i8][VType.t_bad] = VType.t_bad;
195 // WiderType[VType.t_i8][VType.t_bool] = VType.t_i8;
196 // WiderType[VType.t_i8][VType.t_ui1] = VType.t_i8;
197 // WiderType[VType.t_i8][VType.t_i2] = VType.t_i8;
198 // WiderType[VType.t_i8][VType.t_i4] = VType.t_i8;
199 // WiderType[VType.t_i8][VType.t_i8] = VType.t_i8;
200 // WiderType[VType.t_i8][VType.t_dec] = VType.t_dec;
201 // WiderType[VType.t_i8][VType.t_r4] = VType.t_r4;
202 // WiderType[VType.t_i8][VType.t_r8] = VType.t_r8;
203 // WiderType[VType.t_i8][VType.t_char] = VType.t_bad;
204 // WiderType[VType.t_i8][VType.t_str] = VType.t_r8;
205 // WiderType[VType.t_i8][VType.t_date] = VType.t_bad;
207 // WiderType[VType.t_dec][VType.t_bad] = VType.t_bad;
208 // WiderType[VType.t_dec][VType.t_bool] = VType.t_dec;
209 // WiderType[VType.t_dec][VType.t_ui1] = VType.t_dec;
210 // WiderType[VType.t_dec][VType.t_i2] = VType.t_dec;
211 // WiderType[VType.t_dec][VType.t_i4] = VType.t_dec;
212 // WiderType[VType.t_dec][VType.t_i8] = VType.t_dec;
213 // WiderType[VType.t_dec][VType.t_dec] = VType.t_dec;
214 // WiderType[VType.t_dec][VType.t_r4] = VType.t_r4;
215 // WiderType[VType.t_dec][VType.t_r8] = VType.t_r8;
216 // WiderType[VType.t_dec][VType.t_char] = VType.t_bad;
217 // WiderType[VType.t_dec][VType.t_str] = VType.t_r8;
218 // WiderType[VType.t_dec][VType.t_date] = VType.t_bad;
220 // WiderType[VType.t_r4][VType.t_bad] = VType.t_bad;
221 // WiderType[VType.t_r4][VType.t_bool] = VType.t_r4;
222 // WiderType[VType.t_r4][VType.t_ui1] = VType.t_r4;
223 // WiderType[VType.t_r4][VType.t_i2] = VType.t_r4;
224 // WiderType[VType.t_r4][VType.t_i4] = VType.t_r4;
225 // WiderType[VType.t_r4][VType.t_i8] = VType.t_r4;
226 // WiderType[VType.t_r4][VType.t_dec] = VType.t_r4;
227 // WiderType[VType.t_r4][VType.t_r4] = VType.t_r4;
228 // WiderType[VType.t_r4][VType.t_r8] = VType.t_r8;
229 // WiderType[VType.t_r4][VType.t_char] = VType.t_bad;
230 // WiderType[VType.t_r4][VType.t_str] = VType.t_r8;
231 // WiderType[VType.t_r4][VType.t_date] = VType.t_bad;
233 // WiderType[VType.t_r8][VType.t_bad] = VType.t_bad;
234 // WiderType[VType.t_r8][VType.t_bool] = VType.t_r8;
235 // WiderType[VType.t_r8][VType.t_ui1] = VType.t_r8;
236 // WiderType[VType.t_r8][VType.t_i2] = VType.t_r8;
237 // WiderType[VType.t_r8][VType.t_i4] = VType.t_r8;
238 // WiderType[VType.t_r8][VType.t_i8] = VType.t_r8;
239 // WiderType[VType.t_r8][VType.t_dec] = VType.t_r8;
240 // WiderType[VType.t_r8][VType.t_r4] = VType.t_r8;
241 // WiderType[VType.t_r8][VType.t_r8] = VType.t_r8;
242 // WiderType[VType.t_r8][VType.t_char] = VType.t_bad;
243 // WiderType[VType.t_r8][VType.t_str] = VType.t_r8;
244 // WiderType[VType.t_r8][VType.t_date] = VType.t_bad;
246 // WiderType[VType.t_char][VType.t_bad] = VType.t_bad;
247 // WiderType[VType.t_char][VType.t_bool] = VType.t_bad;
248 // WiderType[VType.t_char][VType.t_ui1] = VType.t_bad;
249 // WiderType[VType.t_char][VType.t_i2] = VType.t_bad;
250 // WiderType[VType.t_char][VType.t_i4] = VType.t_bad;
251 // WiderType[VType.t_char][VType.t_i8] = VType.t_bad;
252 // WiderType[VType.t_char][VType.t_dec] = VType.t_bad;
253 // WiderType[VType.t_char][VType.t_r4] = VType.t_bad;
254 // WiderType[VType.t_char][VType.t_r8] = VType.t_bad;
255 // WiderType[VType.t_char][VType.t_char] = VType.t_char;
256 // WiderType[VType.t_char][VType.t_str] = VType.t_str;
257 // WiderType[VType.t_char][VType.t_date] = VType.t_bad;
259 // WiderType[VType.t_str][VType.t_bad] = VType.t_bad;
260 // WiderType[VType.t_str][VType.t_bool] = VType.t_r8;
261 // WiderType[VType.t_str][VType.t_ui1] = VType.t_r8;
262 // WiderType[VType.t_str][VType.t_i2] = VType.t_r8;
263 // WiderType[VType.t_str][VType.t_i4] = VType.t_r8;
264 // WiderType[VType.t_str][VType.t_i8] = VType.t_r8;
265 // WiderType[VType.t_str][VType.t_dec] = VType.t_r8;
266 // WiderType[VType.t_str][VType.t_r4] = VType.t_r8;
267 // WiderType[VType.t_str][VType.t_r8] = VType.t_r8;
268 // WiderType[VType.t_str][VType.t_char] = VType.t_str;
269 // WiderType[VType.t_str][VType.t_str] = VType.t_str;
270 // WiderType[VType.t_str][VType.t_date] = VType.t_date;
272 // WiderType[VType.t_date][VType.t_bad] = VType.t_bad;
273 // WiderType[VType.t_date][VType.t_bool] = VType.t_bad;
274 // WiderType[VType.t_date][VType.t_ui1] = VType.t_bad;
275 // WiderType[VType.t_date][VType.t_i2] = VType.t_bad;
276 // WiderType[VType.t_date][VType.t_i4] = VType.t_bad;
277 // WiderType[VType.t_date][VType.t_i8] = VType.t_bad;
278 // WiderType[VType.t_date][VType.t_dec] = VType.t_bad;
279 // WiderType[VType.t_date][VType.t_r4] = VType.t_bad;
280 // WiderType[VType.t_date][VType.t_r8] = VType.t_bad;
281 // WiderType[VType.t_date][VType.t_char] = VType.t_bad;
282 // WiderType[VType.t_date][VType.t_str] = VType.t_date;
283 // WiderType[VType.t_date][VType.t_date] = VType.t_date;
285 // ConversionClassTable[VType2.t_bad][VType2.t_bad] = VType2.t_bad;
286 // ConversionClassTable[VType2.t_bad][VType2.t_bool] = VType2.t_bad;
287 // ConversionClassTable[VType2.t_bad][VType2.t_ui1] = VType2.t_bad;
288 // ConversionClassTable[VType2.t_bad][VType2.t_char] = VType2.t_bad;
289 // ConversionClassTable[VType2.t_bad][VType2.t_i2] = VType2.t_bad;
290 // ConversionClassTable[VType2.t_bad][VType2.t_i4] = VType2.t_bad;
291 // ConversionClassTable[VType2.t_bad][VType2.t_i8] = VType2.t_bad;
292 // ConversionClassTable[VType2.t_bad][VType2.t_r4] = VType2.t_bad;
293 // ConversionClassTable[VType2.t_bad][VType2.t_r8] = VType2.t_bad;
294 // ConversionClassTable[VType2.t_bad][VType2.t_date] = VType2.t_bad;
295 // ConversionClassTable[VType2.t_bad][VType2.t_dec] = VType2.t_bad;
296 // ConversionClassTable[VType2.t_bad][VType2.t_ref] = VType2.t_bad;
297 // ConversionClassTable[VType2.t_bad][VType2.t_str] = VType2.t_bad;
299 // ConversionClassTable[VType2.t_bool][VType2.t_bad] = VType2.t_bad;
300 // ConversionClassTable[VType2.t_bool][VType2.t_bool] = VType2.t_bool;
301 // ConversionClassTable[VType2.t_bool][VType2.t_ui1] = VType2.t_ui1;
302 // ConversionClassTable[VType2.t_bool][VType2.t_char] = VType2.t_bad;
303 // ConversionClassTable[VType2.t_bool][VType2.t_i2] = VType2.t_ui1;
304 // ConversionClassTable[VType2.t_bool][VType2.t_i4] = VType2.t_ui1;
305 // ConversionClassTable[VType2.t_bool][VType2.t_i8] = VType2.t_ui1;
306 // ConversionClassTable[VType2.t_bool][VType2.t_r4] = VType2.t_ui1;
307 // ConversionClassTable[VType2.t_bool][VType2.t_r8] = VType2.t_ui1;
308 // ConversionClassTable[VType2.t_bool][VType2.t_bad] = VType2.t_bad;
309 // ConversionClassTable[VType2.t_bool][VType2.t_dec] = VType2.t_ui1;
310 // ConversionClassTable[VType2.t_bool][VType2.t_dec] = VType2.t_bad;
311 // ConversionClassTable[VType2.t_bool][VType2.t_str] = VType2.t_ui1;
313 // ConversionClassTable[VType2.t_ui1][VType2.t_bad] = VType2.t_bad;
314 // ConversionClassTable[VType2.t_ui1][VType2.t_bool] = VType2.t_ui1;
315 // ConversionClassTable[VType2.t_ui1][VType2.t_ui1] = VType2.t_bool;
316 // ConversionClassTable[VType2.t_ui1][VType2.t_char] = VType2.t_bad;
317 // ConversionClassTable[VType2.t_ui1][VType2.t_i2] = VType2.t_ui1;
318 // ConversionClassTable[VType2.t_ui1][VType2.t_i4] = VType2.t_ui1;
319 // ConversionClassTable[VType2.t_ui1][VType2.t_i8] = VType2.t_ui1;
320 // ConversionClassTable[VType2.t_ui1][VType2.t_r4] = VType2.t_ui1;
321 // ConversionClassTable[VType2.t_ui1][VType2.t_r8] = VType2.t_ui1;
322 // ConversionClassTable[VType2.t_ui1][VType2.t_bad] = VType2.t_bad;
323 // ConversionClassTable[VType2.t_ui1][VType2.t_dec] = VType2.t_ui1;
324 // ConversionClassTable[VType2.t_ui1][VType2.t_dec] = VType2.t_bad;
325 // ConversionClassTable[VType2.t_ui1][VType2.t_str] = VType2.t_ui1;
327 // ConversionClassTable[VType2.t_char][VType2.t_bad] = VType2.t_bad;
328 // ConversionClassTable[VType2.t_char][VType2.t_bool] = VType2.t_bad;
329 // ConversionClassTable[VType2.t_char][VType2.t_ui1] = VType2.t_bad;
330 // ConversionClassTable[VType2.t_char][VType2.t_char] = VType2.t_bool;
331 // ConversionClassTable[VType2.t_char][VType2.t_i2] = VType2.t_bad;
332 // ConversionClassTable[VType2.t_char][VType2.t_i4] = VType2.t_bad;
333 // ConversionClassTable[VType2.t_char][VType2.t_i8] = VType2.t_bad;
334 // ConversionClassTable[VType2.t_char][VType2.t_r4] = VType2.t_bad;
335 // ConversionClassTable[VType2.t_char][VType2.t_r8] = VType2.t_bad;
336 // ConversionClassTable[VType2.t_char][VType2.t_bad] = VType2.t_bad;
337 // ConversionClassTable[VType2.t_char][VType2.t_dec] = VType2.t_bad;
338 // ConversionClassTable[VType2.t_char][VType2.t_dec] = VType2.t_bad;
339 // ConversionClassTable[VType2.t_char][VType2.t_str] = VType2.t_ui1;
341 // ConversionClassTable[VType2.t_i2][VType2.t_bad] = VType2.t_bad;
342 // ConversionClassTable[VType2.t_i2][VType2.t_bool] = VType2.t_ui1;
343 // ConversionClassTable[VType2.t_i2][VType2.t_ui1] = VType2.t_char;
344 // ConversionClassTable[VType2.t_i2][VType2.t_char] = VType2.t_bad;
345 // ConversionClassTable[VType2.t_i2][VType2.t_i2] = VType2.t_bool;
346 // ConversionClassTable[VType2.t_i2][VType2.t_i4] = VType2.t_ui1;
347 // ConversionClassTable[VType2.t_i2][VType2.t_i8] = VType2.t_ui1;
348 // ConversionClassTable[VType2.t_i2][VType2.t_r4] = VType2.t_ui1;
349 // ConversionClassTable[VType2.t_i2][VType2.t_r8] = VType2.t_ui1;
350 // ConversionClassTable[VType2.t_i2][VType2.t_bad] = VType2.t_bad;
351 // ConversionClassTable[VType2.t_i2][VType2.t_dec] = VType2.t_ui1;
352 // ConversionClassTable[VType2.t_i2][VType2.t_dec] = VType2.t_bad;
353 // ConversionClassTable[VType2.t_i2][VType2.t_str] = VType2.t_ui1;
355 // ConversionClassTable[VType2.t_i4][VType2.t_bad] = VType2.t_bad;
356 // ConversionClassTable[VType2.t_i4][VType2.t_bool] = VType2.t_ui1;
357 // ConversionClassTable[VType2.t_i4][VType2.t_ui1] = VType2.t_char;
358 // ConversionClassTable[VType2.t_i4][VType2.t_char] = VType2.t_bad;
359 // ConversionClassTable[VType2.t_i4][VType2.t_i2] = VType2.t_char;
360 // ConversionClassTable[VType2.t_i4][VType2.t_i4] = VType2.t_bool;
361 // ConversionClassTable[VType2.t_i4][VType2.t_i8] = VType2.t_ui1;
362 // ConversionClassTable[VType2.t_i4][VType2.t_r4] = VType2.t_ui1;
363 // ConversionClassTable[VType2.t_i4][VType2.t_r8] = VType2.t_ui1;
364 // ConversionClassTable[VType2.t_i4][VType2.t_bad] = VType2.t_bad;
365 // ConversionClassTable[VType2.t_i4][VType2.t_dec] = VType2.t_ui1;
366 // ConversionClassTable[VType2.t_i4][VType2.t_dec] = VType2.t_bad;
367 // ConversionClassTable[VType2.t_i4][VType2.t_str] = VType2.t_ui1;
369 // ConversionClassTable[VType2.t_i8][VType2.t_bad] = VType2.t_bad;
370 // ConversionClassTable[VType2.t_i8][VType2.t_bool] = VType2.t_ui1;
371 // ConversionClassTable[VType2.t_i8][VType2.t_ui1] = VType2.t_char;
372 // ConversionClassTable[VType2.t_i8][VType2.t_char] = VType2.t_bad;
373 // ConversionClassTable[VType2.t_i8][VType2.t_i2] = VType2.t_char;
374 // ConversionClassTable[VType2.t_i8][VType2.t_i4] = VType2.t_char;
375 // ConversionClassTable[VType2.t_i8][VType2.t_i8] = VType2.t_bool;
376 // ConversionClassTable[VType2.t_i8][VType2.t_r4] = VType2.t_ui1;
377 // ConversionClassTable[VType2.t_i8][VType2.t_r8] = VType2.t_ui1;
378 // ConversionClassTable[VType2.t_i8][VType2.t_bad] = VType2.t_bad;
379 // ConversionClassTable[VType2.t_i8][VType2.t_dec] = VType2.t_ui1;
380 // ConversionClassTable[VType2.t_i8][VType2.t_dec] = VType2.t_bad;
381 // ConversionClassTable[VType2.t_i8][VType2.t_str] = VType2.t_ui1;
383 // ConversionClassTable[VType2.t_r4][VType2.t_bad] = VType2.t_bad;
384 // ConversionClassTable[VType2.t_r4][VType2.t_bool] = VType2.t_ui1;
385 // ConversionClassTable[VType2.t_r4][VType2.t_ui1] = VType2.t_char;
386 // ConversionClassTable[VType2.t_r4][VType2.t_char] = VType2.t_bad;
387 // ConversionClassTable[VType2.t_r4][VType2.t_i2] = VType2.t_char;
388 // ConversionClassTable[VType2.t_r4][VType2.t_i4] = VType2.t_char;
389 // ConversionClassTable[VType2.t_r4][VType2.t_i8] = VType2.t_char;
390 // ConversionClassTable[VType2.t_r4][VType2.t_r4] = VType2.t_bool;
391 // ConversionClassTable[VType2.t_r4][VType2.t_r8] = VType2.t_ui1;
392 // ConversionClassTable[VType2.t_r4][VType2.t_bad] = VType2.t_bad;
393 // ConversionClassTable[VType2.t_r4][VType2.t_dec] = VType2.t_char;
394 // ConversionClassTable[VType2.t_r4][VType2.t_dec] = VType2.t_bad;
395 // ConversionClassTable[VType2.t_r4][VType2.t_str] = VType2.t_ui1;
397 // ConversionClassTable[VType2.t_r8][VType2.t_bad] = VType2.t_bad;
398 // ConversionClassTable[VType2.t_r8][VType2.t_bool] = VType2.t_ui1;
399 // ConversionClassTable[VType2.t_r8][VType2.t_ui1] = VType2.t_char;
400 // ConversionClassTable[VType2.t_r8][VType2.t_char] = VType2.t_bad;
401 // ConversionClassTable[VType2.t_r8][VType2.t_i2] = VType2.t_char;
402 // ConversionClassTable[VType2.t_r8][VType2.t_i4] = VType2.t_char;
403 // ConversionClassTable[VType2.t_r8][VType2.t_i8] = VType2.t_char;
404 // ConversionClassTable[VType2.t_r8][VType2.t_r4] = VType2.t_char;
405 // ConversionClassTable[VType2.t_r8][VType2.t_r8] = VType2.t_bool;
406 // ConversionClassTable[VType2.t_r8][VType2.t_bad] = VType2.t_bad;
407 // ConversionClassTable[VType2.t_r8][VType2.t_dec] = VType2.t_char;
408 // ConversionClassTable[VType2.t_r8][VType2.t_dec] = VType2.t_bad;
409 // ConversionClassTable[VType2.t_r8][VType2.t_str] = VType2.t_ui1;
411 // ConversionClassTable[VType2.t_bad][VType2.t_bad] = VType2.t_bad;
412 // ConversionClassTable[VType2.t_bad][VType2.t_bool] = VType2.t_bad;
413 // ConversionClassTable[VType2.t_bad][VType2.t_ui1] = VType2.t_bad;
414 // ConversionClassTable[VType2.t_bad][VType2.t_char] = VType2.t_bad;
415 // ConversionClassTable[VType2.t_bad][VType2.t_i2] = VType2.t_bad;
416 // ConversionClassTable[VType2.t_bad][VType2.t_i4] = VType2.t_bad;
417 // ConversionClassTable[VType2.t_bad][VType2.t_i8] = VType2.t_bad;
418 // ConversionClassTable[VType2.t_bad][VType2.t_r4] = VType2.t_bad;
419 // ConversionClassTable[VType2.t_bad][VType2.t_r8] = VType2.t_bad;
420 // ConversionClassTable[VType2.t_bad][VType2.t_bad] = VType2.t_bool;
421 // ConversionClassTable[VType2.t_bad][VType2.t_dec] = VType2.t_bad;
422 // ConversionClassTable[VType2.t_bad][VType2.t_dec] = VType2.t_bad;
423 // ConversionClassTable[VType2.t_bad][VType2.t_str] = VType2.t_ui1;
425 // ConversionClassTable[VType2.t_dec][VType2.t_bad] = VType2.t_bad;
426 // ConversionClassTable[VType2.t_dec][VType2.t_bool] = VType2.t_ui1;
427 // ConversionClassTable[VType2.t_dec][VType2.t_ui1] = VType2.t_char;
428 // ConversionClassTable[VType2.t_dec][VType2.t_char] = VType2.t_bad;
429 // ConversionClassTable[VType2.t_dec][VType2.t_i2] = VType2.t_char;
430 // ConversionClassTable[VType2.t_dec][VType2.t_i4] = VType2.t_char;
431 // ConversionClassTable[VType2.t_dec][VType2.t_i8] = VType2.t_char;
432 // ConversionClassTable[VType2.t_dec][VType2.t_r4] = VType2.t_ui1;
433 // ConversionClassTable[VType2.t_dec][VType2.t_r8] = VType2.t_ui1;
434 // ConversionClassTable[VType2.t_dec][VType2.t_bad] = VType2.t_bad;
435 // ConversionClassTable[VType2.t_dec][VType2.t_dec] = VType2.t_bool;
436 // ConversionClassTable[VType2.t_dec][VType2.t_dec] = VType2.t_bad;
437 // ConversionClassTable[VType2.t_dec][VType2.t_str] = VType2.t_ui1;
439 // ConversionClassTable[VType2.t_dec][VType2.t_bad] = VType2.t_bad;
440 // ConversionClassTable[VType2.t_dec][VType2.t_bool] = VType2.t_bad;
441 // ConversionClassTable[VType2.t_dec][VType2.t_ui1] = VType2.t_bad;
442 // ConversionClassTable[VType2.t_dec][VType2.t_char] = VType2.t_bad;
443 // ConversionClassTable[VType2.t_dec][VType2.t_i2] = VType2.t_bad;
444 // ConversionClassTable[VType2.t_dec][VType2.t_i4] = VType2.t_bad;
445 // ConversionClassTable[VType2.t_dec][VType2.t_i8] = VType2.t_bad;
446 // ConversionClassTable[VType2.t_dec][VType2.t_r4] = VType2.t_bad;
447 // ConversionClassTable[VType2.t_dec][VType2.t_r8] = VType2.t_bad;
448 // ConversionClassTable[VType2.t_dec][VType2.t_bad] = VType2.t_bad;
449 // ConversionClassTable[VType2.t_dec][VType2.t_dec] = VType2.t_bad;
450 // ConversionClassTable[VType2.t_dec][VType2.t_dec] = VType2.t_bad;
451 // ConversionClassTable[VType2.t_dec][VType2.t_str] = VType2.t_bad;
453 // ConversionClassTable[VType2.t_str][VType2.t_bad] = VType2.t_bad;
454 // ConversionClassTable[VType2.t_str][VType2.t_bool] = VType2.t_ui1;
455 // ConversionClassTable[VType2.t_str][VType2.t_ui1] = VType2.t_ui1;
456 // ConversionClassTable[VType2.t_str][VType2.t_char] = VType2.t_char;
457 // ConversionClassTable[VType2.t_str][VType2.t_i2] = VType2.t_ui1;
458 // ConversionClassTable[VType2.t_str][VType2.t_i4] = VType2.t_ui1;
459 // ConversionClassTable[VType2.t_str][VType2.t_i8] = VType2.t_ui1;
460 // ConversionClassTable[VType2.t_str][VType2.t_r4] = VType2.t_ui1;
461 // ConversionClassTable[VType2.t_str][VType2.t_r8] = VType2.t_ui1;
462 // ConversionClassTable[VType2.t_str][VType2.t_bad] = VType2.t_ui1;
463 // ConversionClassTable[VType2.t_str][VType2.t_dec] = VType2.t_ui1;
464 // ConversionClassTable[VType2.t_str][VType2.t_dec] = VType2.t_bad;
465 // ConversionClassTable[VType2.t_str][VType2.t_str] = VType2.t_bool;
467 // VType2FromTypeCode[TypeCode.Boolean] = VType2.t_bool;
468 // VType2FromTypeCode[TypeCode.Byte] = VType2.t_ui1;
469 // VType2FromTypeCode[TypeCode.Int16] = VType2.t_i2;
470 // VType2FromTypeCode[TypeCode.Int32] = VType2.t_i4;
471 // VType2FromTypeCode[TypeCode.Int64] = VType2.t_i8;
472 // VType2FromTypeCode[TypeCode.Decimal] = VType2.t_dec;
473 // VType2FromTypeCode[TypeCode.Single] = VType2.t_r4;
474 // VType2FromTypeCode[TypeCode.Double] = VType2.t_r8;
475 // VType2FromTypeCode[TypeCode.Char] = VType2.t_char;
476 // VType2FromTypeCode[TypeCode.string] = VType2.t_str;
477 // VType2FromTypeCode[TypeCode.DateTime] = VType2.t_date;
479 // VTypeFromTypeCode[TypeCode.Boolean] = VType.t_bool;
480 // VTypeFromTypeCode[TypeCode.Byte] = VType.t_ui1;
481 // VTypeFromTypeCode[TypeCode.Int16] = VType.t_i2;
482 // VTypeFromTypeCode[TypeCode.Int32] = VType.t_i4;
483 // VTypeFromTypeCode[TypeCode.Int64] = VType.t_i8;
484 // VTypeFromTypeCode[TypeCode.Decimal] = VType.t_dec;
485 // VTypeFromTypeCode[TypeCode.Single] = VType.t_r4;
486 // VTypeFromTypeCode[TypeCode.Double] = VType.t_r8;
487 // VTypeFromTypeCode[TypeCode.Char] = VType.t_char;
488 // VTypeFromTypeCode[TypeCode.string] = VType.t_str;
489 // VTypeFromTypeCode[TypeCode.DateTime] = VType.t_date;
491 // TypeCodeFromVType[VType.t_bool] = TypeCode.Boolean;
492 // TypeCodeFromVType[VType.t_ui1] = TypeCode.Byte;
493 // TypeCodeFromVType[VType.t_i2] = TypeCode.Int16;
494 // TypeCodeFromVType[VType.t_i4] = TypeCode.Int32;
495 // TypeCodeFromVType[VType.t_i8] = TypeCode.Int64;
496 // TypeCodeFromVType[VType.t_dec] = TypeCode.Decimal;
497 // TypeCodeFromVType[VType.t_r4] = TypeCode.Single;
498 // TypeCodeFromVType[VType.t_r8] = TypeCode.Double;
499 // TypeCodeFromVType[VType.t_char] = TypeCode.Char;
500 // TypeCodeFromVType[VType.t_str] = TypeCode.string;
501 // TypeCodeFromVType[VType.t_date] = TypeCode.DateTime;
503 // TypeFromTypeCode[TypeCode.Boolean] = Type.BooleanType;
504 // TypeFromTypeCode[TypeCode.Byte] = Type.ByteType;
505 // TypeFromTypeCode[TypeCode.Int16] = Type.Int16Type;
506 // TypeFromTypeCode[TypeCode.Int32] = Type.Int32Type;
507 // TypeFromTypeCode[TypeCode.Int64] = Type.Int64Type;
508 // TypeFromTypeCode[TypeCode.Decimal] = Type.DecimalType;
509 // TypeFromTypeCode[TypeCode.Single] = Type.SingleType;
510 // TypeFromTypeCode[TypeCode.Double] = Type.DoubleType;
511 // TypeFromTypeCode[TypeCode.Char] = Type.CharType;
512 // TypeFromTypeCode[TypeCode.string] = Type.StringType;
513 // TypeFromTypeCode[TypeCode.DateTime] = Type.DateTimeType;
514 // TypeFromTypeCode[TypeCode.SByte] = Type.SByteType;
515 // TypeFromTypeCode[TypeCode.UInt16] = Type.UInt16Type;
516 // TypeFromTypeCode[TypeCode.UInt32] = Type.UInt32Type;
517 // TypeFromTypeCode[TypeCode.UInt64] = Type.UInt64Type;
518 // TypeFromTypeCode[TypeCode.object] = Type.ObjectType;
519 // TypeFromTypeCode[TypeCode.DBNull] = Type.DBNullType;
522 private static void checkIfAddValidObjects(
527 if (tc1
== TypeCode
.Object
|| tc1
== TypeCode
.SByte
528 || tc1
== TypeCode
.UInt16
|| tc1
== TypeCode
.UInt32
529 || tc1
== TypeCode
.UInt64
)
530 throwNoValidOperator(obj1
, obj2
);
531 if (tc2
== TypeCode
.Object
|| tc2
== TypeCode
.SByte
532 || tc2
== TypeCode
.UInt16
|| tc2
== TypeCode
.UInt32
533 || tc2
== TypeCode
.UInt64
)
534 throwNoValidOperator(obj1
, obj2
);
538 public static object AddObj(object obj1
, object obj2
) {
539 TypeCode tc1
= getTypeCode(obj1
);
540 if (obj1
!= null && (obj1
is char[]))
541 obj1
= new string((char[]) obj1
);
543 TypeCode tc2
= getTypeCode(obj2
);
544 if (obj2
!= null && (obj2
is char[]))
545 obj2
= new string((char[]) obj2
);
547 checkIfAddValidObjects(obj1
,obj2
,tc1
,tc2
);
549 if (tc1
== TypeCode
.DBNull
|| tc2
== TypeCode
.DBNull
)
550 return getAddDBNull(obj1
,obj2
,tc1
,tc2
);
551 else if (tc1
== TypeCode
.DateTime
|| tc2
== TypeCode
.DateTime
)
552 return getAddDateTime(obj1
,obj2
,tc1
,tc2
);
553 else if (tc1
== TypeCode
.Char
|| tc2
== TypeCode
.Char
)
554 return getAddChar(obj1
,obj2
,tc1
,tc2
);
556 if (tc1
== TypeCode
.Empty
)
558 else if (tc2
== TypeCode
.Empty
)
561 if (tc1
== TypeCode
.String
&& tc2
== TypeCode
.String
)
562 return StringType
.FromObject(obj1
) + StringType
.FromObject(obj2
);
563 else if (tc1
== TypeCode
.String
|| tc2
== TypeCode
.String
)
564 return getAddStringObject(obj1
,obj2
,tc1
,tc2
);
566 if (tc1
== TypeCode
.Double
|| tc2
== TypeCode
.Double
)
567 return getAddDouble(obj1
,obj2
,tc1
,tc2
);
568 else if (tc1
== TypeCode
.Single
|| tc2
== TypeCode
.Single
)
569 return getAddSingle(obj1
,obj2
,tc1
,tc2
);
570 else if(tc1
== TypeCode
.Decimal
|| tc2
== TypeCode
.Decimal
)
571 return getAddDecimal(obj1
,obj2
,tc1
,tc2
);
572 else if (tc1
== TypeCode
.Int64
|| tc2
== TypeCode
.Int64
)
573 return getAddInt64(obj1
,obj2
,tc1
,tc2
);
574 else if (tc1
== TypeCode
.Int32
|| tc2
== TypeCode
.Int32
)
575 return getAddInt32(obj1
,obj2
,tc1
,tc2
);
576 else if (tc1
== TypeCode
.Int16
|| tc2
== TypeCode
.Int16
)
577 return getAddInt16(obj1
,obj2
,tc1
,tc2
);
578 else if (tc1
== TypeCode
.Boolean
|| tc2
== TypeCode
.Boolean
)
579 return getAddInt16(obj1
,obj2
,tc1
,tc2
);
580 else if (tc1
== TypeCode
.Byte
|| tc2
== TypeCode
.Byte
)
581 return getAddByte(obj1
,obj2
,tc1
,tc2
);
583 throwNoValidOperator(obj1
, obj2
);
587 private static object getAddDBNull(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
588 if (tc1
== TypeCode
.DBNull
) {
589 if (tc2
== TypeCode
.String
)
592 throwNoValidOperator(obj1
, obj2
);
594 else if (tc1
== TypeCode
.String
)
597 throwNoValidOperator(obj1
, obj2
);
601 private static object getAddChar(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
602 if (tc1
== TypeCode
.Char
) {
603 if (tc2
== TypeCode
.Char
|| tc2
== TypeCode
.String
)
604 return StringType
.FromObject(obj1
) + StringType
.FromObject(obj2
);
606 throwNoValidOperator(obj1
, obj2
);
608 else if (tc2
== TypeCode
.Char
) {
609 if (tc1
== TypeCode
.Char
|| tc1
== TypeCode
.String
)
610 return StringType
.FromObject(obj1
) + StringType
.FromObject(obj2
);
612 throwNoValidOperator(obj1
, obj2
);
617 private static object getAddDateTime(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
618 if (tc1
== TypeCode
.DateTime
) {
619 if (tc2
== TypeCode
.DateTime
|| tc2
== TypeCode
.String
)
620 return obj1
.ToString() + obj2
.ToString();
622 throwNoValidOperator(obj1
, obj2
);
624 else if (tc2
== TypeCode
.DateTime
) {
625 if (tc1
== TypeCode
.DateTime
|| tc1
== TypeCode
.String
)
626 return obj1
.ToString() + obj2
.ToString();
628 throwNoValidOperator(obj1
, obj2
);
633 private static object getAddByte(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
634 byte d1
= convertObjectToByte(obj1
,tc1
);
635 byte d2
= convertObjectToByte(obj2
,tc2
);
636 short s
= (short) (d1
+ d2
);
637 if (s
>= 0 && s
<= 255)
642 private static object getAddDouble(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
643 double d1
= convertObjectToDouble(obj1
,tc1
);
644 double d2
= convertObjectToDouble(obj2
,tc2
);
648 private static object getAddDecimal(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
649 Decimal d1
= convertObjectToDecimal(obj1
,tc1
);
650 Decimal d2
= convertObjectToDecimal(obj2
,tc2
);
651 return Decimal
.Add(d1
,d2
);
654 private static object getAddInt64(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
655 Decimal d1
= convertObjectToDecimal(obj1
,tc1
);
656 Decimal d2
= convertObjectToDecimal(obj2
,tc2
);
657 Decimal sum
= Decimal
.Add(d1
,d2
);
659 Decimal
.Compare(sum
, new Decimal(long.MaxValue
)) <= 0
660 && Decimal
.Compare(sum
, new Decimal(long.MinValue
))
662 return Decimal
.ToInt64(sum
);
667 private static object getAddInt32(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
668 long d1
= convertObjectToLong(obj1
,tc1
);
669 long d2
= convertObjectToLong(obj2
,tc2
);
671 if (sum
>= Int32
.MinValue
&& sum
<= Int32
.MaxValue
)
676 private static object getAddInt16(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
677 int d1
= convertObjectToInt(obj1
,tc1
);
678 int d2
= convertObjectToInt(obj2
,tc2
);
680 if (sum
>= short.MinValue
&& sum
<= short.MaxValue
)
686 private static object getAddSingle(object obj1
,object obj2
,TypeCode tc1
,TypeCode tc2
) {
687 float d1
= convertObjectToFloat(obj1
,tc1
);
688 float d2
= convertObjectToFloat(obj2
,tc2
);
690 double sum
= (double) d1
+ (double) d2
;
691 if (sum
<= 3.40282e+038 && sum
>= -3.40282e+038)
693 if (Double
.IsInfinity(sum
) &&
694 (Single
.IsInfinity(d1
) || Single
.IsInfinity(d2
)))
700 private static int toVBBool(IConvertible conv
) {
701 if (conv
.ToBoolean(null))
708 private static object getAddStringObject(object s1
, object s2
,TypeCode tc1
,TypeCode tc2
) {
709 double d1
= convertObjectToDouble(s1
,tc1
);
710 double d2
= convertObjectToDouble(s1
,tc2
);
715 public static object BitAndObj(object obj1
, object obj2
) {
716 Type type1
= obj1
.GetType();
717 Type type2
= obj2
.GetType();
718 TypeCode typeCode
= GetWidestType(obj1
, obj2
, false);
720 if (obj1
== null && obj2
== null)
722 else if (typeCode
== TypeCode
.Boolean
) {
724 return ((bool)obj1
) & ((bool)obj2
);
725 return ((short)obj1
) & ((short)obj2
);
727 else if (typeCode
== TypeCode
.Byte
) {
728 byte val
= (byte)(ByteType
.FromObject(obj1
)
729 & ByteType
.FromObject(obj2
));
730 return createByteAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
732 else if (typeCode
== TypeCode
.Int16
) {
734 (short)(ShortType
.FromObject(obj1
)
735 & ShortType
.FromObject(obj2
));
736 return createShortAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
738 else if (typeCode
== TypeCode
.Int32
) {
739 Int32 val
= IntegerType
.FromObject(obj1
) & IntegerType
.FromObject(obj2
);
740 return createIntAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
742 else if (typeCode
== TypeCode
.Int64
) {
743 long val
= LongType
.FromObject(obj1
) & LongType
.FromObject(obj2
);
744 return createLongAccordingToEnumCond(val
, type1
, type2
, obj1
, obj2
);
746 else if (typeCode
== TypeCode
.Single
|| typeCode
== TypeCode
.Double
747 || typeCode
== TypeCode
.Decimal
|| typeCode
== TypeCode
.String
) {
748 long val
= LongType
.FromObject(obj1
) & LongType
.FromObject(obj2
);
752 throw new InvalidCastException(
753 Utils
.GetResourceString(
754 "NoValidOperator_TwoOperands",
755 Utils
.VBFriendlyName(obj1
),
756 Utils
.VBFriendlyName(obj2
)));
759 private static object createByteAccordingToEnumCond(
765 bool isEnum1
= type1
.IsEnum
;
766 bool isEmum2
= type2
.IsEnum
;
767 if (isEnum1
&& isEmum2
&& type1
!= type2
)
770 return Enum
.ToObject(type1
, val
);
772 throw new InvalidCastException(
773 Utils
.GetResourceString(
774 "NoValidOperator_TwoOperands",
775 Utils
.VBFriendlyName(obj1
),
776 Utils
.VBFriendlyName(obj2
)));
777 return Enum
.ToObject(type2
, val
);
780 private static object createShortAccordingToEnumCond(
786 bool isEnum1
= type1
.IsEnum
;
787 bool isEmum2
= type2
.IsEnum
;
788 if (isEnum1
&& isEmum2
&& type1
!= type2
)
791 return Enum
.ToObject(type1
, val
);
793 throw new InvalidCastException(
794 Utils
.GetResourceString(
795 "NoValidOperator_TwoOperands",
796 Utils
.VBFriendlyName(obj1
),
797 Utils
.VBFriendlyName(obj2
)));
798 return Enum
.ToObject(type2
, val
);
801 private static object createIntAccordingToEnumCond(
807 bool isEnum1
= type1
.IsEnum
;
808 bool isEmum2
= type2
.IsEnum
;
809 if (isEnum1
&& isEmum2
&& type1
!= type2
)
812 return Enum
.ToObject(type1
, val
);
814 throw new InvalidCastException(
815 Utils
.GetResourceString(
816 "NoValidOperator_TwoOperands",
817 Utils
.VBFriendlyName(obj1
),
818 Utils
.VBFriendlyName(obj2
)));
819 return Enum
.ToObject(type2
, val
);
822 private static object createLongAccordingToEnumCond(
828 bool isEnum1
= type1
.IsEnum
;
829 bool isEmum2
= type2
.IsEnum
;
830 if (isEnum1
&& isEmum2
&& type1
!= type2
)
833 return Enum
.ToObject(type1
, val
);
835 throw new InvalidCastException(
836 Utils
.GetResourceString(
837 "NoValidOperator_TwoOperands",
838 Utils
.VBFriendlyName(obj1
),
839 Utils
.VBFriendlyName(obj2
)));
840 return Enum
.ToObject(type2
, val
);
844 public static object BitOrObj(object obj1
, object obj2
) {
845 Type type1
= obj1
.GetType();
846 Type type2
= obj2
.GetType();
847 TypeCode typeCode
= GetWidestType(obj1
, obj2
, false);
849 if (obj1
== null && obj2
== null)
851 else if (typeCode
== TypeCode
.Boolean
) {
853 return BooleanType
.FromObject(obj1
)| BooleanType
.FromObject(obj2
);
854 return (short)( (ushort)ShortType
.FromObject(obj1
) | (ushort)ShortType
.FromObject(obj2
));
856 else if (typeCode
== TypeCode
.Byte
) {
857 byte val
= (byte)(ByteType
.FromObject(obj1
)
858 | ByteType
.FromObject(obj2
));
859 return createByteAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
861 else if (typeCode
== TypeCode
.Int16
) {
862 short val
= (short) ((ushort) ShortType
.FromObject(obj1
)
863 | (ushort)ShortType
.FromObject(obj2
));
864 return createShortAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
866 else if (typeCode
== TypeCode
.Int32
) {
867 Int32 val
= IntegerType
.FromObject(obj1
) | IntegerType
.FromObject(obj2
);
868 return createIntAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
870 else if (typeCode
== TypeCode
.Int64
) {
871 long val
= LongType
.FromObject(obj1
) | LongType
.FromObject(obj2
);
872 return createLongAccordingToEnumCond(val
, type1
, type2
, obj1
, obj2
);
874 else if (typeCode
== TypeCode
.Single
|| typeCode
== TypeCode
.Double
875 || typeCode
== TypeCode
.Decimal
|| typeCode
== TypeCode
.String
) {
876 long val
= LongType
.FromObject(obj1
) | LongType
.FromObject(obj2
);
880 throw new InvalidCastException(
881 Utils
.GetResourceString(
882 "NoValidOperator_TwoOperands",
883 Utils
.VBFriendlyName(obj1
),
884 Utils
.VBFriendlyName(obj2
)));
888 public static object BitXorObj(object obj1
, object obj2
) {
889 Type type1
= obj1
.GetType();
890 Type type2
= obj2
.GetType();
891 TypeCode typeCode
= GetWidestType(obj1
, obj2
, false);
893 if (obj1
== null && obj2
== null)
895 else if (typeCode
== TypeCode
.Boolean
) {
897 return BooleanType
.FromObject(obj1
)^ BooleanType
.FromObject(obj2
);
898 return (short) (ShortType
.FromObject(obj1
) ^ ShortType
.FromObject(obj2
));
900 else if (typeCode
== TypeCode
.Byte
) {
901 byte val
= (Byte
) (ByteType
.FromObject(obj1
)
902 ^ ByteType
.FromObject(obj2
));
903 return createByteAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
905 else if (typeCode
== TypeCode
.Int16
) {
907 (short) (ShortType
.FromObject(obj1
)
908 ^ ShortType
.FromObject(obj2
));
909 return createShortAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
911 else if (typeCode
== TypeCode
.Int32
) {
912 Int32 val
= IntegerType
.FromObject(obj1
) ^ IntegerType
.FromObject(obj2
);
913 return createIntAccordingToEnumCond(val
,type1
,type2
,obj1
,obj2
);
915 else if (typeCode
== TypeCode
.Int64
) {
916 long val
= LongType
.FromObject(obj1
) ^ LongType
.FromObject(obj2
);
917 return createLongAccordingToEnumCond(val
, type1
, type2
, obj1
, obj2
);
919 else if (typeCode
== TypeCode
.Single
|| typeCode
== TypeCode
.Double
920 || typeCode
== TypeCode
.Decimal
|| typeCode
== TypeCode
.String
) {
921 long val
= LongType
.FromObject(obj1
) ^ LongType
.FromObject(obj2
);
925 throw new InvalidCastException(
926 Utils
.GetResourceString(
927 "NoValidOperator_TwoOperands",
928 Utils
.VBFriendlyName(obj1
),
929 Utils
.VBFriendlyName(obj2
)));
932 internal static object CTypeHelper(object obj
, TypeCode toType
) {
933 return CTypeHelper(obj
, toType
.GetType());//toType.getValue));
936 internal static object CTypeHelper(object obj
, int toType
) {
940 case (int)TypeCode
.Boolean
:
941 return BooleanType
.FromObject(obj
);
942 case (int)TypeCode
.Byte
:
943 return ByteType
.FromObject(obj
);
944 case (int)TypeCode
.Int16
:
945 return ShortType
.FromObject(obj
);
946 case (int)TypeCode
.Int32
:
947 return IntegerType
.FromObject(obj
);
948 case (int)TypeCode
.Int64
:
949 return LongType
.FromObject(obj
);
950 case (int)TypeCode
.Decimal
:
951 return DecimalType
.FromObject(obj
);
952 case (int)TypeCode
.Single
:
953 return SingleType
.FromObject(obj
);
954 case (int)TypeCode
.Double
:
955 return DoubleType
.FromObject(obj
);
956 case (int)TypeCode
.String
:
957 return StringType
.FromObject(obj
);
958 case (int)TypeCode
.Char
:
959 return CharType
.FromObject(obj
);
960 case (int)TypeCode
.DateTime
:
961 return DateType
.FromObject(obj
);
965 throw new InvalidCastException(// ClassCastException(
966 Utils
.GetResourceString(
967 "InvalidCast_FromTo",
968 Utils
.VBFriendlyName(obj
),
969 Utils
.VBFriendlyName(ObjectType
.TypeFromTypeCode(toType
))));
974 public static object CTypeHelper(object obj
, Type toType
) {
978 //TODO: how to tell if is truly type of object
979 //if (toType == Type.ObjectType)
982 Type type
= obj
.GetType();
983 // if (toType.IsByRef) {
984 // toType = toType.GetElementType();
988 // local1 = local1.GetElementType();
992 TypeCode tc
= Type
.GetTypeCode(toType
);
993 if (tc
== TypeCode
.Object
) {
994 if (toType
.IsAssignableFrom(type
))
998 // && toType == char[].class).GetType()
999 // return CharArrayType.FromString((string) obj);
1001 throw new InvalidCastException(
1002 Utils
.GetResourceString(
1003 "InvalidCast_FromTo",
1004 Utils
.VBFriendlyName(type
),
1005 Utils
.VBFriendlyName(toType
)));
1008 object retVal
= CTypeHelper(obj
, tc
);
1010 return Enum
.ToObject(toType
,retVal
);
1014 //checked + string//make typecode
1016 internal static TypeCode
GetWidestType(TypeCode type1
, TypeCode type2
) {
1017 int index1
= getVTypeFromTypeCode(type1
);
1018 int index2
= getVTypeFromTypeCode(type2
);
1019 //return getTypeCodeFromVType(WiderType(index1,index2));
1021 throw new NotImplementedException("GetWidest type nneds repair");
1022 //return (TypeCode)getTypeCodeFromVType((int)WiderType[(int)type1,(int)type2]);
1025 internal static TypeCode
GetWidestType(object obj1
, TypeCode typeCode2
) {
1028 TypeCode tc1
= getTypeCode(obj1
);
1029 return GetWidestType(tc1
,typeCode2
);
1032 private static TypeCode
getTypeCode(object obj
) {
1033 IConvertible iConvertible
= null;
1035 if (obj
is IConvertible
) {
1036 iConvertible
= (IConvertible
)obj
;
1038 if (iConvertible
!= null) {
1039 typeCode
= iConvertible
.GetTypeCode();
1041 else if (obj
== null) {
1042 typeCode
= TypeCode
.Empty
;
1044 else if (obj
is string) {
1045 typeCode
= TypeCode
.String
;
1047 else if (obj
is char[]) {
1048 typeCode
= TypeCode
.String
;
1051 typeCode
= TypeCode
.Object
;
1056 internal static TypeCode
GetWidestType(object obj1
, object obj2
, bool IsAdd
) {
1057 TypeCode typeCode1
= getTypeCode(obj1
);
1058 TypeCode typeCode2
= getTypeCode(obj1
);
1065 ((typeCode1
== TypeCode
.DBNull
&& typeCode2
== TypeCode
.String
) ||
1066 (typeCode1
== TypeCode
.String
&& typeCode2
== TypeCode
.DBNull
)))
1067 return TypeCode
.DBNull
;
1069 return GetWidestType(typeCode1
,typeCode2
);
1074 private static TypeCode
getTypeCodeFromVType(int vartype
) {
1075 throw new NotImplementedException("get typecode from vtype needs help");
1077 //return TypeCodeFromVType[vartype];
1081 private static int getVTypeFromTypeCode(TypeCode type
) {
1082 throw new NotImplementedException("get typecode from vtype needs help");
1084 //return VTypeFromTypeCode[type];
1088 public static object GetObjectValuePrimitive(object o
) {
1089 if (o
== null || !(o
is IConvertible
))
1091 IConvertible iConv
= (IConvertible
)o
;
1092 TypeCode tc
= getTypeCode(o
);
1094 //this four type code are converted in this way since they can also
1096 case TypeCode
.Byte
:
1097 return iConv
.ToByte(null);
1098 case TypeCode
.Int16
:
1099 return iConv
.ToInt16(null);
1100 case TypeCode
.Int32
:
1101 return iConv
.ToInt32(null);
1102 case TypeCode
.Int64
:
1103 return iConv
.ToInt64(null);
1110 private static object getDivDecimal(object obj1
, object obj2
,TypeCode tc1
,TypeCode tc2
) {
1111 Decimal dec1
= convertObjectToDecimal(obj1
,tc1
);
1112 Decimal dec2
= convertObjectToDecimal(obj2
,tc2
);
1114 return Decimal
.Divide(dec1
, dec2
);
1116 catch(OverflowException e
) {
1117 e
.ToString();//TODO: Dumb way to fix compiler warning about unused e
1118 float val1
= Convert
.ToSingle(dec1
);
1119 float val2
= Convert
.ToSingle(dec2
);
1120 float val3
= val1
/val2
;
1127 private static object getDivDouble(object s1
, object s2
, TypeCode tc1
,TypeCode tc2
) {
1128 double d1
= convertObjectToDouble(s1
,tc1
);
1129 double d2
= convertObjectToDouble(s2
,tc2
);
1134 private static object getDivSingle(object obj1
, object obj2
,TypeCode tc1
, TypeCode tc2
) {
1135 float d1
= convertObjectToFloat(obj1
,tc1
);
1136 float d2
= convertObjectToFloat(obj2
,tc2
);
1138 float sum
= d1
/ d2
;
1139 if (float.IsInfinity(d1
)) {
1140 if (float.IsInfinity(d1
) || float.IsInfinity(d2
))
1142 return (double) d1
/ (double) d2
;
1147 private static void checkIfValidObjects(
1152 if (tc1
== TypeCode
.Object
|| tc1
== TypeCode
.DBNull
1153 || tc1
== TypeCode
.Char
|| tc1
== TypeCode
.SByte
1154 || tc1
== TypeCode
.UInt16
|| tc1
== TypeCode
.UInt32
1155 || tc1
== TypeCode
.UInt64
|| tc1
== TypeCode
.DateTime
)
1156 throwNoValidOperator(obj1
, obj2
);
1157 if (tc2
== TypeCode
.Object
|| tc2
== TypeCode
.DBNull
1158 || tc2
== TypeCode
.Char
|| tc2
== TypeCode
.SByte
1159 || tc2
== TypeCode
.UInt16
|| tc2
== TypeCode
.UInt32
1160 || tc2
== TypeCode
.UInt64
|| tc2
== TypeCode
.DateTime
)
1161 throwNoValidOperator(obj1
, obj2
);
1165 public static object DivObj(object o1
, object o2
) {
1166 TypeCode tc1
= getTypeCode(o1
);
1167 TypeCode tc2
= getTypeCode(o2
);
1169 checkIfValidObjects(o1
,o2
,tc1
,tc2
);
1171 if (tc2
== TypeCode
.Empty
)
1172 throw new DivideByZeroException(
1173 /*Environment.GetResourceString(*/"Arg_DivideByZero")/*)*/;
1175 if (tc1
== TypeCode
.String
|| tc2
== TypeCode
.String
)
1176 return getDivDouble(o1
,o2
,tc1
,tc2
);
1177 else if (tc1
== TypeCode
.Empty
)
1178 return getDivDouble((double)0, o2
,TypeCode
.Double
,tc2
);
1179 else if (tc1
== TypeCode
.Double
|| tc2
== TypeCode
.Double
)
1180 return getDivDouble(o1
,o2
,tc1
,tc2
);
1181 else if (tc1
== TypeCode
.Single
|| tc2
== TypeCode
.Single
)
1182 return getDivSingle(o1
, o2
,tc1
,tc2
);
1183 else if (tc1
== TypeCode
.Decimal
|| tc2
== TypeCode
.Decimal
)
1184 return getDivDecimal(o1
, o2
,tc1
,tc2
);
1186 return getDivDouble(o1
, o2
,tc1
,tc2
);
1190 private static IConvertible
toVBBoolConv(IConvertible conv
) {
1191 if (conv
.ToBoolean(null))
1196 private static object getIDivideByte(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1197 byte d1
= convertObjectToByte(o1
,tc1
);
1198 byte d2
= convertObjectToByte(o2
,tc2
);
1202 private static object getIDivideInt16(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1203 short d1
= convertObjectToShort(o1
,tc1
);
1204 short d2
= convertObjectToShort(o2
,tc2
);
1205 return (int)((short) (d1
/ d2
));
1208 private static object getIDivideInt32(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1209 int d1
= convertObjectToInt(o1
,tc1
);
1210 int d2
= convertObjectToInt(o2
,tc2
);
1214 private static object getIDivideInt64(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1215 long d1
= convertObjectToLong(o1
,tc1
);
1216 long d2
= convertObjectToLong(o2
,tc2
);
1221 public static object IDivObj(object o1
, object o2
) {
1222 TypeCode tc1
= getTypeCode(o1
);
1223 TypeCode tc2
= getTypeCode(o2
);
1224 checkIfValidObjects(o1
,o2
,tc1
,tc2
);
1226 if (tc2
== TypeCode
.Empty
)
1227 throw new DivideByZeroException(
1228 /*Environment.GetResourceString(*/"Arg_DivideByZero")/*)*/;
1229 else if (tc1
== TypeCode
.Empty
) {
1230 if (tc2
== TypeCode
.Byte
)
1232 else if (tc2
== TypeCode
.Int16
)
1234 else if (tc2
== TypeCode
.Int32
)
1239 else if (tc1
== TypeCode
.String
|| tc2
== TypeCode
.String
||
1240 tc1
== TypeCode
.Decimal
|| tc2
== TypeCode
.Decimal
||
1241 tc1
== TypeCode
.Double
|| tc2
== TypeCode
.Double
||
1242 tc1
== TypeCode
.Single
|| tc2
== TypeCode
.Single
||
1243 tc1
== TypeCode
.Int64
|| tc2
== TypeCode
.Int64
)
1244 return getIDivideInt64(o1
,o2
,tc1
,tc2
);
1245 else if (tc1
== TypeCode
.Int32
|| tc2
== TypeCode
.Int32
)
1246 return getIDivideInt32(o1
,o2
,tc1
,tc2
);
1247 else if (tc1
== TypeCode
.Int16
|| tc2
== TypeCode
.Int16
)
1248 return getIDivideInt16(o1
,o2
,tc1
,tc2
);
1249 else if (tc1
== TypeCode
.Byte
|| tc2
== TypeCode
.Byte
)
1250 return getIDivideByte(o1
,o2
,tc1
,tc2
);
1252 return getIDivideInt16(o1
,o2
,tc1
,tc2
);
1255 private static object negObj(
1261 case TypeCode
.Empty
:
1263 case TypeCode
.Boolean
:
1264 if(((bool)obj
) == true)return (short)1;
1266 //int boolValue = (((ClrBoolean)obj).ToBoolean(null) == true)? 1 :0;
1267 //return (short)boolValue;
1269 case TypeCode
.Byte
:
1270 conv
= (IConvertible
)obj
;
1271 short byteValue
= (short) (0 - conv
.ToByte(null));
1272 return (short)byteValue
;
1273 case TypeCode
.Int16
:
1274 conv
= (IConvertible
)obj
;
1275 int shortValue
= (0 - conv
.ToInt16(null));
1276 return (int)shortValue
;
1277 case TypeCode
.Int32
:
1278 conv
= (IConvertible
)obj
;
1279 long intValue
= (0 - conv
.ToInt32(null));
1281 case TypeCode
.Int64
:
1282 conv
= (IConvertible
)obj
;
1283 Int64 longValue
= conv
.ToInt64(null);
1284 if (longValue
== Int64
.MinValue
)return Decimal
.Negate(conv
.ToDecimal(null));
1286 case TypeCode
.Decimal
:
1287 return Decimal
.Negate((Decimal
) obj
);
1288 case TypeCode
.Single
:
1290 case TypeCode
.Double
:
1291 return (double)(0 - (double) obj
);
1292 case TypeCode
.String
:
1293 return (double)(0 - DoubleType
.FromString((string) obj
));
1296 throw new InvalidCastException(
1297 Utils
.GetResourceString(
1298 "NoValidOperator_OneOperand",
1299 Utils
.VBFriendlyName(obj
)));
1304 internal static bool IsTypeOf(Type typSrc
, Type typParent
) {
1305 if (typSrc
== typParent
)
1307 return typSrc
.IsSubclassOf(typParent
);
1310 internal static bool IsWideningConversion(Type FromType
, Type ToType
) {
1311 TypeCode typeCode1
= Type
.GetTypeCode(FromType
);
1312 TypeCode typeCode2
= Type
.GetTypeCode(ToType
);
1313 if (typeCode1
== TypeCode
.Object
) {
1315 // if ((FromType == char[].class.GetType()) &&
1316 // (typeCode2 == TypeCode.String || ToType == char[].class).GetType())
1320 // if (typeCode2 != TypeCode.Object)
1324 // if (!FromType.IsArray() || !ToType.IsArray())
1326 // return ToType.IsAssignableFrom(FromType);
1328 // //if (FromType.GetArrayRank() == ToType.GetArrayRank())
1330 // // return ToType.GetElementType().IsAssignableFrom(FromType.GetElementType());
1337 if (typeCode2
== TypeCode
.Object
) {
1339 // if (ToType == char[].class.GetType() && typeCode1 == TypeCode.string)
1343 return ToType
.IsAssignableFrom(FromType
);
1345 if (ToType
.IsEnum
) {
1348 int index1
= getVType2FromTypeCode(typeCode2
);
1349 int index2
= getVType2FromTypeCode(typeCode1
);
1350 int cC
= ConversionClassTable
[index1
,index2
];
1351 if (cC
!= 3 /*CC.Wide*/ && cC
!= 1 /*CC.Same*/) {//TODO replace hard coded values with enum, after enum is converted
1361 internal static bool IsWiderNumeric(Type Type1
, Type Type2
) {
1362 TypeCode typeCode1
= Type
.GetTypeCode(Type1
);
1363 TypeCode typeCode2
= Type
.GetTypeCode(Type2
);
1364 if (!Utils
.IsNumericType(Type1
) || !Utils
.IsNumericType(Type2
)) {
1367 if (typeCode1
== TypeCode
.Boolean
|| typeCode2
== TypeCode
.Boolean
) {
1374 int index1
= getVTypeFromTypeCode(typeCode1
);
1375 int index2
= getVTypeFromTypeCode(typeCode2
);
1376 throw new NotImplementedException("MSVB.CS.IsWiderNumeric needs help");
1378 //return )WiderType[index1,index2] == getVTypeFromTypeCode(typeCode1);
1382 public static bool LikeObj(
1385 CompareMethod compareOption
) {
1386 return StringType
.StrLike(
1387 StringType
.FromObject(vLeft
),
1388 StringType
.FromObject(vRight
),
1392 private static object getModByte(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1393 byte i1
= convertObjectToByte(o1
,tc1
);
1394 byte i2
= convertObjectToByte(o2
,tc2
);
1395 return (byte) (i1
% i2
);
1398 private static object getModDecimal(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1399 Decimal dec1
= convertObjectToDecimal(o1
,tc1
);
1400 Decimal dec2
= convertObjectToDecimal(o2
,tc2
);
1401 return Decimal
.Remainder(dec1
, dec2
);
1404 private static object getModDouble(object o1
, object o2
, TypeCode tc1
,TypeCode tc2
) {
1405 double d1
= convertObjectToDouble(o1
,tc1
);
1406 double d2
= convertObjectToDouble(o1
,tc1
);
1410 private static object getModInt16(object o1
, object o2
, TypeCode tc1
,TypeCode tc2
) {
1411 short i1
= convertObjectToShort(o1
,tc1
);
1412 short i2
= convertObjectToShort(o2
,tc2
);
1413 Int32 mod
= i1
% i2
;
1414 if (mod
< -32768 || mod
> 32767)
1419 private static object getModInt32(object o1
, object o2
, TypeCode tc1
,TypeCode tc2
) {
1420 int i1
= convertObjectToInt(o1
,tc1
);
1421 int i2
= convertObjectToInt(o1
,tc1
);
1422 long mod
= (long) i1
% (long) i2
;
1423 if (mod
< 2147483648L || mod
> 2147483647L)
1428 private static object getModInt64(object o1
, object o2
, TypeCode tc1
,TypeCode tc2
) {
1429 long l1
= convertObjectToLong(o1
,tc1
);
1430 long l2
= convertObjectToLong(o2
,tc2
);
1435 public static object ModObj(object o1
, object o2
) {
1436 TypeCode tc1
= getTypeCode(o1
);
1437 TypeCode tc2
= getTypeCode(o2
);
1439 checkIfValidObjects(o1
,o2
,tc1
,tc2
);
1441 if (tc2
== TypeCode
.Empty
)
1442 throw new DivideByZeroException(
1443 /*Environment.GetResourceString(*/"Arg_DivideByZero"/*)*/);
1444 else if (tc1
== TypeCode
.Empty
)
1445 return createZero(tc2
);
1446 else if (tc1
== TypeCode
.String
|| tc2
== TypeCode
.String
)
1447 return getModDouble(o1
,o2
,tc1
,tc2
);
1448 else if (tc1
== TypeCode
.Double
|| tc2
== TypeCode
.Double
)
1449 return getModDouble(o1
,o2
,tc1
,tc2
);
1450 else if (tc1
== TypeCode
.Single
|| tc2
== TypeCode
.Single
)
1451 return getModSingle(o1
,o2
,tc1
,tc2
);
1452 else if (tc1
== TypeCode
.Decimal
|| tc2
== TypeCode
.Decimal
)
1453 return getModDecimal(o1
,o2
,tc1
,tc2
);
1454 else if (tc1
== TypeCode
.Int64
|| tc2
== TypeCode
.Int64
)
1455 return getModInt64(o1
,o2
,tc1
,tc2
);
1456 else if (tc1
== TypeCode
.Int32
|| tc2
== TypeCode
.Int32
)
1457 return getModInt32(o1
,o2
,tc1
,tc2
);
1458 else if (tc1
== TypeCode
.Int16
|| tc2
== TypeCode
.Int16
)
1459 return getModInt16(o1
,o2
,tc1
,tc2
);
1460 else if (tc1
== TypeCode
.Byte
&& tc2
== TypeCode
.Byte
)
1461 return getModByte(o1
,o2
,tc1
,tc2
);
1463 return getModInt16(o1
,o2
,tc1
,tc2
);
1468 private static int getVType2FromTypeCode(TypeCode typeCode
) {
1469 return VType2FromTypeCode
[(int)typeCode
];
1472 private static object getModSingle(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1473 float sng1
= convertObjectToFloat(o1
,tc1
);
1474 float sng2
= convertObjectToFloat(o2
,tc2
);
1475 return (float)(sng1
% sng2
);
1478 private static object getMulByte(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1479 byte b1
= convertObjectToByte(o1
,tc1
);
1480 byte b2
= convertObjectToByte(o2
,tc2
);
1482 if (i1
>= 0 && i1
<= 255)
1484 if (i1
>= -32768 && i1
<= 32767)
1489 private static object getMulDouble(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1490 double d1
= convertObjectToDouble(o1
,tc1
);
1491 double d2
= convertObjectToDouble(o2
,tc2
);
1492 return (double)(d1
* d2
);
1495 private static object getMulInt16(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1496 short s1
= convertObjectToShort(o1
,tc1
);
1497 short s2
= convertObjectToShort(o2
,tc2
);
1499 if (i1
>= -32768 && i1
<= 32767)
1504 private static object getMulInt32(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1505 int i1
= convertObjectToInt(o1
,tc1
);
1506 int i2
= convertObjectToInt(o2
,tc2
);
1507 long l1
= (long) i1
* (long) i2
;
1508 if (l1
>= 2147483648L && l1
<= 2147483647L)
1513 private static object getMulSingle(object o1
, object o2
, TypeCode tc1
,TypeCode tc2
) {
1514 float f1
= convertObjectToFloat(o1
,tc1
);
1515 float f2
= convertObjectToFloat(o2
,tc2
);
1516 double d
= (double) f1
* (double) f2
;
1517 if (d
<= 3.40282e+038 && d
>= -3.40282e+038)
1519 if (double.IsInfinity(d
)
1520 && float.IsInfinity(f1
)
1521 || float.IsInfinity(f2
))
1526 private static object getMulDecimal(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1527 Decimal dec1
= convertObjectToDecimal(o1
,tc1
);
1528 Decimal dec2
= convertObjectToDecimal(o1
,tc1
);
1531 Decimal dec3
= Decimal
.Multiply(dec1
, dec2
);
1534 catch (OverflowException exp
) {
1535 exp
.ToString();//dumb way to fix compiler warning about exp not used
1536 double d1
= Convert
.ToDouble(dec1
);
1537 double d2
= Convert
.ToDouble(dec2
);
1539 return (float)(d1
* d2
);
1543 private static object getMulInt64(object o1
,object o2
, TypeCode tc1
,TypeCode tc2
) {
1544 long l1
= convertObjectToLong(o1
,tc1
);
1545 long l2
= convertObjectToLong(o2
,tc2
);
1546 if (long.MaxValue
/ Math
.Abs(l1
) >= Math
.Abs(l2
))
1549 Decimal dec1
= new Decimal(l1
);
1550 Decimal dec2
= new Decimal(l2
);
1553 Decimal dec3
= Decimal
.Multiply(dec1
, dec2
);
1556 catch (OverflowException exp
) {
1557 exp
.ToString();//dumb way to fix exp not used compiler warning
1558 double d1
= (double) l1
* (double) l2
;
1564 private static object createZero(TypeCode tc
) {
1566 case TypeCode
.Boolean
:
1570 case TypeCode
.Int16
:
1572 case TypeCode
.Int32
:
1574 case TypeCode
.Int64
:
1576 case TypeCode
.Single
:
1577 return (float)(0.0f
);
1578 case TypeCode
.Double
:
1580 case TypeCode
.Decimal
:
1581 return Decimal
.Zero
;
1582 case TypeCode
.String
:
1589 public static object MulObj(object o1
, object o2
) {
1590 TypeCode tc1
= getTypeCode(o1
);
1591 TypeCode tc2
= getTypeCode(o2
);
1592 checkIfValidObjects(o1
,o2
,tc1
,tc2
);
1594 if (tc1
== TypeCode
.Empty
&& tc2
== TypeCode
.Empty
)
1596 else if (tc1
== TypeCode
.Empty
)
1597 return createZero(tc2
);
1598 else if (tc2
== TypeCode
.Empty
)
1599 return createZero(tc1
);
1600 else if (tc1
== TypeCode
.String
|| tc1
== TypeCode
.String
)
1601 return getMulDouble(o1
,o2
,tc1
,tc2
);
1602 else if (tc1
== TypeCode
.Double
|| tc1
== TypeCode
.Double
)
1603 return getMulDouble(o1
,o2
,tc1
,tc2
);
1604 else if (tc1
== TypeCode
.Single
|| tc1
== TypeCode
.Single
)
1605 return getMulSingle(o1
,o2
,tc1
,tc2
);
1606 else if (tc1
== TypeCode
.Decimal
|| tc1
== TypeCode
.Decimal
)
1607 return getMulDecimal(o1
,o2
,tc1
,tc2
);
1608 else if (tc1
== TypeCode
.Int64
|| tc1
== TypeCode
.Int64
)
1609 return getMulInt64(o1
,o2
,tc1
,tc2
);
1610 else if (tc1
== TypeCode
.Int32
|| tc1
== TypeCode
.Int32
)
1611 return getMulInt32(o1
,o2
,tc1
,tc2
);
1612 else if (tc1
== TypeCode
.Int16
|| tc1
== TypeCode
.Int16
)
1613 return getMulInt16(o1
,o2
,tc1
,tc2
);
1614 else if (tc1
== TypeCode
.Byte
|| tc1
== TypeCode
.Byte
)
1615 return getMulByte(o1
,o2
,tc1
,tc2
);
1617 return getMulInt16(o1
,o2
,tc1
,tc2
);
1621 public static object NegObj(object obj
) {
1622 TypeCode tc
= getTypeCode(obj
);
1623 return negObj(obj
, tc
);
1626 public static object NotObj(object obj
) {
1629 TypeCode tc
= getTypeCode(obj
);
1635 case TypeCode
.Boolean
:
1637 //new ClrBoolean(!((ClrBoolean)obj).ToBoolean(null));
1638 case TypeCode
.Byte
:
1639 type
= obj
.GetType();
1640 conv
= (IConvertible
)obj
;
1641 byte byteVal
= (byte) ~
(conv
.ToByte(null));
1643 return Enum
.ToObject(type
, byteVal
);
1645 case TypeCode
.Int16
:
1646 type
= obj
.GetType();
1647 conv
= (IConvertible
)obj
;
1648 short shortVal
= (short) ~
(conv
.ToInt16(null));
1650 return Enum
.ToObject(type
, shortVal
);
1652 case TypeCode
.Int32
:
1653 type
= obj
.GetType();
1654 conv
= (IConvertible
)obj
;
1655 int intVal
= ~
(conv
.ToInt32(null));
1657 return Enum
.ToObject(type
, intVal
);
1659 case TypeCode
.Int64
:
1660 type
= obj
.GetType();
1661 conv
= (IConvertible
)obj
;
1662 long longVal
= ~
(conv
.ToInt64(null));
1664 return Enum
.ToObject(type
, longVal
);
1666 case TypeCode
.Single
:
1667 val
= LongType
.FromObject(obj
);
1669 case TypeCode
.Double
:
1670 val
= LongType
.FromObject(obj
);
1672 case TypeCode
.Decimal
:
1673 val
= LongType
.FromObject(obj
);
1675 case TypeCode
.String
:
1676 val
= LongType
.FromObject(obj
);
1680 throw new InvalidCastException(
1681 Utils
.GetResourceString(
1682 "NoValidOperator_OneOperand",
1683 Utils
.VBFriendlyName(obj
)));
1686 private static object createZeroForCompare(TypeCode tc
) {
1688 case TypeCode
.Boolean
:
1694 case TypeCode
.Int16
:
1696 case TypeCode
.Int32
:
1698 case TypeCode
.Int64
:
1700 case TypeCode
.Single
:
1702 case TypeCode
.Double
:
1704 case TypeCode
.Decimal
:
1705 return Decimal
.Zero
;
1706 case TypeCode
.DateTime
:
1708 case TypeCode
.String
:
1715 public static int ObjTst(object o1
, object o2
, bool textCompare
) {
1716 TypeCode tc1
= getTypeCode(o1
);
1717 TypeCode tc2
= getTypeCode(o2
);
1718 IComparable icomp1
= (IComparable
)o1
;
1719 IComparable icomp2
= (IComparable
)o2
;
1721 if (tc1
== TypeCode
.Empty
&& tc2
== TypeCode
.Empty
)
1723 else if (tc1
== TypeCode
.Empty
)
1724 return icomp2
.CompareTo(createZeroForCompare(tc2
));
1725 else if (tc2
== TypeCode
.Empty
)
1726 return icomp1
.CompareTo(createZeroForCompare(tc1
));
1727 else if (tc1
== TypeCode
.DateTime
|| tc2
== TypeCode
.DateTime
)
1728 return getObjTstDateTime(o1
,o2
,tc1
,tc2
);
1729 else if (tc1
== TypeCode
.Char
&& tc2
== TypeCode
.Char
)
1730 return getObjTstChar(o1
,o2
,tc1
,tc2
);
1731 else if ((tc1
== TypeCode
.Boolean
&& tc2
== TypeCode
.String
)||
1732 (tc2
== TypeCode
.Boolean
&& tc1
== TypeCode
.String
) )
1733 return getObjTstBoolean(o1
,o2
,tc1
,tc2
);
1734 else if (tc1
== TypeCode
.Double
|| tc2
== TypeCode
.Double
)
1735 return getObjTstDouble(o1
,o2
,tc1
,tc2
);
1736 else if (tc1
== TypeCode
.Single
|| tc2
== TypeCode
.Single
)
1737 return getObjTstSingle(o1
,o2
,tc1
,tc2
);
1738 else if (tc1
== TypeCode
.Decimal
|| tc2
== TypeCode
.Decimal
)
1739 return getObjTstDecimal(o1
,o2
,tc1
,tc2
);
1740 else if (tc1
== TypeCode
.Int64
|| tc2
== TypeCode
.Int64
)
1741 return getObjTstInt64(o1
,o2
,tc1
,tc2
);
1742 else if (tc1
== TypeCode
.Int32
|| tc2
== TypeCode
.Int32
)
1743 return getObjTstInt32(o1
,o2
,tc1
,tc2
);
1744 else if (tc1
== TypeCode
.Int16
|| tc2
== TypeCode
.Int16
)
1745 return getObjTstInt16(o1
,o2
,tc1
,tc2
);
1746 else if (tc1
== TypeCode
.Byte
&& tc2
== TypeCode
.Byte
)
1747 return getObjTstByte(o1
,o2
,tc1
,tc2
);
1748 else if (tc1
== TypeCode
.String
|| tc2
== TypeCode
.String
)
1749 return getObjTstString(o1
,o2
,tc1
,tc2
);
1751 return getObjTstInt16(o1
,o2
,tc1
,tc2
);
1754 private static int getObjTstString(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1755 string s1
= (tc1
== TypeCode
.String
)?(string)o1
:o1
.ToString();
1756 string s2
= (tc2
== TypeCode
.String
)?(string)o2
:o2
.ToString();
1757 return s1
.CompareTo(s2
);
1760 private static int getObjTstBoolean(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1761 IConvertible iconv1
= (IConvertible
)o1
;
1762 IConvertible iconv2
= (IConvertible
)o2
;
1763 bool b1
= iconv1
.ToBoolean(null);
1764 bool b2
= iconv2
.ToBoolean(null);
1772 private static int getObjTstByte(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1773 byte by1
= convertObjectToByte(o1
,tc1
);
1774 byte by2
= convertObjectToByte(o2
,tc2
);
1782 private static int getObjTstChar(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1783 char ch1
= convertObjectToChar(o1
,tc1
);
1784 char ch2
= convertObjectToChar(o2
,tc2
);
1792 private static int getObjTstDateTime(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1793 DateTime var1
= convertObjectToDateTime(o1
,tc1
);
1794 DateTime var2
= convertObjectToDateTime(o2
,tc2
);
1795 long time1
= Convert
.ToInt32(var1
);//Java code var1.getCalendar().getTime().getTime();
1796 long time2
= Convert
.ToInt32(var2
);//Java code var2.getCalendar().getTime().getTime();
1804 private static int getObjTstDecimal(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1805 Decimal dec1
= convertObjectToDecimal(o1
,tc1
);
1806 Decimal dec2
= convertObjectToDecimal(o2
,tc2
);
1807 int res
= Decimal
.Compare(dec1
, dec2
);
1815 private static int getObjTstDouble(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1816 double d1
= convertObjectToDouble(o1
,tc1
);
1817 double d2
= convertObjectToDouble(o2
,tc2
);
1825 private static int getObjTstInt16(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1826 short s1
= convertObjectToShort(o1
,tc1
);
1827 short s2
= convertObjectToShort(o2
,tc2
);
1835 private static int getObjTstInt32(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1836 int i1
= convertObjectToInt(o1
,tc1
);
1837 int i2
= convertObjectToInt(o2
,tc2
);
1845 private static int getObjTstInt64(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1846 long l1
= convertObjectToLong(o1
,tc1
);
1847 long l2
= convertObjectToLong(o1
,tc1
);
1855 private static int getObjTstSingle(object o1
,object o2
,TypeCode tc1
,TypeCode tc2
) {
1856 float f1
= convertObjectToFloat(o1
,tc1
);
1857 float f2
= convertObjectToFloat(o2
,tc2
);
1865 private static int getObjTstStringObject(object s1
, object s2
,TypeCode tc1
,TypeCode tc2
) {
1866 double d1
= convertObjectToDouble(s1
,tc1
);
1867 double d2
= convertObjectToDouble(s2
,tc2
);
1868 return ObjectType
.getObjTstDouble(s1
,s2
,tc1
, tc2
);
1871 public static object PlusObj(object obj
) {
1872 TypeCode tc
= getTypeCode(obj
);
1873 if (tc
== TypeCode
.Empty
)
1875 else if (tc
== TypeCode
.Boolean
) {
1876 IConvertible conv
= (IConvertible
)obj
;
1877 //java return new short((short) conv.ToInt16(null));
1878 return (short)conv
.ToInt16(null);//cast to short probably not needed.
1880 else if (tc
== TypeCode
.String
)
1881 return DoubleType
.FromObject(obj
);
1882 else if (tc
== TypeCode
.Byte
|| tc
== TypeCode
.Int16
1883 || tc
== TypeCode
.Int32
|| tc
== TypeCode
.Int64
1884 || tc
== TypeCode
.Single
|| tc
== TypeCode
.Double
1885 || tc
== TypeCode
.Decimal
)
1888 throw new InvalidCastException(
1889 Utils
.GetResourceString(
1890 "NoValidOperator_OneOperand",
1891 Utils
.VBFriendlyName(obj
)));
1894 public static object PowObj(object obj1
, object obj2
) {
1895 if (obj1
== null || obj2
== null)
1897 TypeCode tc1
= getTypeCode(obj1
);
1898 TypeCode tc2
= getTypeCode(obj2
);
1899 TypeCode widestType
= GetWidestType(tc1
,tc2
);
1901 if (widestType
== TypeCode
.Byte
|| widestType
== TypeCode
.Boolean
1902 || widestType
== TypeCode
.Int16
|| widestType
== TypeCode
.Int32
1903 || widestType
== TypeCode
.Int64
|| widestType
== TypeCode
.Single
1904 || widestType
== TypeCode
.Double
|| widestType
== TypeCode
.Decimal
1905 || widestType
== TypeCode
.String
)
1906 return (double)Math
.Pow(DoubleType
.FromObject(obj1
),DoubleType
.FromObject(obj2
));
1907 //return new ClrDouble(
1908 // java.lang.Math.pow(
1909 // DoubleType.FromObject(obj1),
1910 // DoubleType.FromObject(obj2)));
1912 throw new InvalidCastException(
1913 Utils
.GetResourceString(
1914 "NoValidOperator_OneOperand",
1915 Utils
.VBFriendlyName(obj1
)));
1919 public static object StrCatObj(object vLeft
, object vRight
) {
1920 if (vLeft
is DBNull
&& vRight
is DBNull
)
1921 return DBNull
.Value
;
1922 return StringType
.FromObject(vLeft
) + StringType
.FromObject(vRight
);
1925 private static object getSubByte(object o1
, object o2
, TypeCode tc1
,TypeCode tc2
) {
1926 byte byte1
= convertObjectToByte(o1
,tc1
);
1927 byte byte2
= convertObjectToByte(o2
,tc2
);
1928 short s
= (short) (byte1
- byte2
);
1929 if (s
>= 0 && s
<= 255)
1934 private static object getSubDecimal(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1935 Decimal dec1
= convertObjectToDecimal(o1
,tc1
);
1936 Decimal dec2
= convertObjectToDecimal(o2
,tc2
);
1938 Decimal dec3
= Decimal
.Subtract(dec1
, dec2
);
1941 catch (OverflowException exp
) {
1942 exp
.ToString();//dumb way to fix compiler warning about exp not used
1944 double d1
= Decimal
.ToDouble(dec1
);
1945 double d2
= Decimal
.ToDouble(dec2
);
1947 return (double)(d1
* d2
);
1951 private static object getSubInt16(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1952 short s1
= convertObjectToShort(o1
,tc1
);
1953 short s2
= convertObjectToShort(o2
,tc2
);
1955 if (res
>= -32768 && res
<= 32767)
1960 private static object getSubInt32(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1961 int i1
= convertObjectToInt(o1
,tc1
);
1962 int i2
= convertObjectToInt(o2
,tc2
);
1963 long res
= (long) i1
- (long) i2
;
1964 if (res
>= 2147483648L && res
<= 2147483647L)
1969 private static object getSubInt64(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1970 long l1
= convertObjectToLong(o1
,tc1
);
1971 long l2
= convertObjectToLong(o2
,tc2
);
1973 //Java code if (Long.MAX_VALUE - java.lang.Math.abs(l1) <= java.lang.Math.abs(l2))
1974 if (long.MaxValue
- Math
.Abs(l1
) <= Math
.Abs(l2
))
1977 Decimal dec1
= new Decimal(l1
);
1978 Decimal dec2
= new Decimal(l2
);
1980 Decimal dec3
= Decimal
.Subtract(dec1
, dec2
);
1984 private static object getSubSingle(object o1
, object o2
,TypeCode tc1
,TypeCode tc2
) {
1985 float d1
= convertObjectToFloat(o1
,tc1
);
1986 float d2
= convertObjectToFloat(o2
,tc2
);
1987 double res
= (double) d1
- (double) d2
;
1988 if (res
<= 3.40282e+038 && res
>= -3.40282e+038)
1990 if (double.IsInfinity(res
)
1991 && float.IsInfinity(d1
)
1992 || float.IsInfinity(d2
))
1997 private static DateTime
convertObjectToDateTime(object o1
, TypeCode tc1
) {
1998 DateTime dateTime
= new DateTime(0);//java code null
2001 dateTime
= DateType
.FromString((string) o1
);
2002 else if (o1
is IConvertible
) {
2003 dateTime
= ((IConvertible
) o1
).ToDateTime(null);
2009 private static char convertObjectToChar(object o1
, TypeCode tc1
) {
2010 char char1
= (char)0;
2013 char1
= CharType
.FromString((string)o1
);
2014 else if (o1
is IConvertible
) {
2015 if (tc1
== TypeCode
.Boolean
) {
2016 char1
= (char)toVBBool((IConvertible
)o1
);
2019 char1
= (char)((IConvertible
)o1
).ToChar(null);
2025 private static byte convertObjectToByte(object o1
, TypeCode tc1
) {
2029 byte1
= (byte)ByteType
.FromString((string)o1
);
2030 else if (o1
is IConvertible
) {
2031 if (tc1
== TypeCode
.Boolean
) {
2032 byte1
= (byte)toVBBool((IConvertible
)o1
);
2035 byte1
= (byte)((IConvertible
)o1
).ToByte(null);
2041 private static short convertObjectToShort(object o1
, TypeCode tc1
) {
2045 s1
= ShortType
.FromString((string)o1
);
2046 else if (o1
is IConvertible
) {
2047 if (tc1
== TypeCode
.Boolean
) {
2048 s1
= (short)toVBBool((IConvertible
)o1
);
2051 s1
= ((IConvertible
)o1
).ToInt16(null);
2057 private static int convertObjectToInt(object o1
, TypeCode tc1
) {
2061 i1
= IntegerType
.FromString((string)o1
);
2062 else if (o1
is IConvertible
) {
2063 if (tc1
== TypeCode
.Boolean
) {
2064 i1
= (int)toVBBool((IConvertible
)o1
);
2067 i1
= ((IConvertible
)o1
).ToInt32(null);
2073 private static Decimal
convertObjectToDecimal(object o1
, TypeCode tc1
) {
2074 Decimal dec1
= 0;//java code null;
2077 dec1
= DecimalType
.FromString((string)o1
);
2078 else if (o1
is IConvertible
) {
2079 if (tc1
== TypeCode
.Boolean
) {
2080 dec1
= toVBBoolConv((IConvertible
)o1
).ToDecimal(null);
2083 dec1
= ((IConvertible
)o1
).ToDecimal(null);
2089 private static long convertObjectToLong(object o1
, TypeCode tc1
) {
2093 l1
= LongType
.FromString((string)o1
);
2094 else if (o1
is IConvertible
) {
2095 if (tc1
== TypeCode
.Boolean
) {
2096 l1
= (long)toVBBool((IConvertible
)o1
);
2099 l1
= ((IConvertible
)o1
).ToInt64(null);
2105 private static float convertObjectToFloat(object o1
, TypeCode tc1
) {
2109 d1
= SingleType
.FromString((string)o1
);
2110 else if (o1
is IConvertible
) {
2111 if (tc1
== TypeCode
.Boolean
) {
2112 d1
= (float)toVBBool((IConvertible
)o1
);
2115 d1
= ((IConvertible
)o1
).ToSingle(null);
2121 private static double convertObjectToDouble(object o1
, TypeCode tc1
) {
2125 d1
= DoubleType
.FromString((string)o1
);
2126 else if (o1
is IConvertible
) {
2127 if (tc1
== TypeCode
.Boolean
) {
2128 d1
= (double) toVBBool((IConvertible
)o1
);
2131 d1
= ((IConvertible
)o1
).ToDouble(null);
2137 private static object getSubDouble(object s1
, object s2
,TypeCode tc1
,TypeCode tc2
) {
2138 double d1
= convertObjectToDouble(s1
,tc1
);
2139 double d2
= convertObjectToDouble(s2
,tc2
);
2144 public static object SubObj(object o1
, object o2
) {
2145 TypeCode tc1
= getTypeCode(o1
);
2146 TypeCode tc2
= getTypeCode(o2
);
2147 checkIfValidObjects(o1
,o2
,tc1
,tc2
);
2149 if (tc1
== TypeCode
.Empty
&& tc2
== TypeCode
.Empty
)
2151 else if (tc2
== TypeCode
.Empty
)
2153 else if (tc1
== TypeCode
.Empty
)
2154 return negObj(o2
, tc2
);
2155 else if (tc1
== TypeCode
.Double
|| tc2
== TypeCode
.Double
)
2156 return getSubDouble(o1
,o2
,tc1
,tc2
);
2157 else if (tc1
== TypeCode
.String
|| tc2
== TypeCode
.String
)
2158 return getSubDouble(o1
,o2
,tc1
,tc2
);
2159 else if (tc1
== TypeCode
.Single
|| tc2
== TypeCode
.Single
)
2160 return getSubSingle(o1
,o2
,tc1
,tc2
);
2161 else if (tc1
== TypeCode
.Decimal
|| tc2
== TypeCode
.Decimal
)
2162 return getSubDecimal(o1
,o2
,tc1
,tc2
);
2163 else if (tc1
== TypeCode
.Int64
|| tc2
== TypeCode
.Int64
)
2164 return getSubInt64(o1
,o2
,tc1
,tc2
);
2165 else if (tc1
== TypeCode
.Int32
|| tc2
== TypeCode
.Int32
)
2166 return getSubInt32(o1
,o2
,tc1
,tc2
);
2167 else if (tc1
== TypeCode
.Int16
|| tc2
== TypeCode
.Int16
)
2168 return getSubInt16(o1
,o2
,tc1
,tc2
);
2169 else if (tc1
== TypeCode
.Byte
&& tc2
== TypeCode
.Byte
)
2170 return getSubByte(o1
,o2
,tc1
,tc2
);
2172 return getSubInt16(o1
,o2
,tc1
,tc2
);
2177 private static void throwNoValidOperator(object obj1
, object obj2
) {
2178 string obj1MsgStr
= "'Nothing'";
2179 string obj2MsgStr
= "'Nothing'";
2180 string obj1Name
= Utils
.VBFriendlyName(obj1
);
2181 string obj2Name
= Utils
.VBFriendlyName(obj2
);
2184 Utils
.GetResourceString(
2185 "NoValidOperator_StringType1",
2187 else if (obj1
!= null)
2189 Utils
.GetResourceString(
2190 "NoValidOperator_NonStringType1",
2194 Utils
.GetResourceString(
2195 "NoValidOperator_StringType1",
2197 else if (obj2
!= null)
2199 Utils
.GetResourceString(
2200 "NoValidOperator_NonStringType1",
2203 throw new InvalidCastException(
2204 Utils
.GetResourceString(
2205 "NoValidOperator_TwoOperands",
2210 public static object ShiftLeftObj (object o1
, int amount
) {
2211 IConvertible convertible1
= (IConvertible
)o1
;
2212 TypeCode tc
= getTypeCode(o1
);
2214 if (tc
== TypeCode
.Empty
)
2216 else if (tc
== TypeCode
.Boolean
)
2217 return (short) ((((short) - convertible1
.ToInt16(null))
2219 else if (tc
== TypeCode
.Byte
)
2220 return (byte) ((convertible1
.ToByte(null) << (amount
& 7)));
2221 else if (tc
== TypeCode
.Int16
)
2222 return (short) ((convertible1
.ToInt16(null) << (amount
& 15)));
2223 else if (tc
== TypeCode
.Int32
)
2224 return (int)convertible1
.ToInt32(null) << (amount
& 31);
2226 tc
== TypeCode
.Int64
2227 || tc
== TypeCode
.Single
2228 || tc
== TypeCode
.Double
2229 || tc
== TypeCode
.Decimal
)
2230 return (Int64
)(convertible1
.ToInt64(null) << (amount
& 63));
2231 else if (tc
== TypeCode
.String
)
2232 return (long)((LongType
.FromString(convertible1
.ToString(null))
2235 throw new InvalidCastException(
2236 Utils
.GetResourceString(
2237 "NoValidOperator_OneOperand",
2238 Utils
.VBFriendlyName(o1
)));
2241 public static object ShiftRightObj (object o1
, int amount
) {
2242 IConvertible convertible1
= (IConvertible
)o1
;
2243 TypeCode tc
= getTypeCode(o1
);
2245 if (tc
== TypeCode
.Empty
)
2247 else if (tc
== TypeCode
.Boolean
)
2248 return (short) ((((short) - convertible1
.ToInt16(null))
2250 else if (tc
== TypeCode
.Byte
)
2251 return (byte) ((convertible1
.ToByte(null) >> (amount
& 7)));
2252 else if (tc
== TypeCode
.Int16
)
2253 return (short) ((convertible1
.ToInt16(null) >> (amount
& 15)));
2254 else if (tc
== TypeCode
.Int32
)
2255 return (int)convertible1
.ToInt32(null) >> (amount
& 31);
2257 tc
== TypeCode
.Int64
2258 || tc
== TypeCode
.Single
2259 || tc
== TypeCode
.Double
2260 || tc
== TypeCode
.Decimal
)
2261 return (long)(convertible1
.ToInt64(null) >> (amount
& 63));
2262 else if (tc
== TypeCode
.String
)
2263 return (long)(LongType
.FromString(convertible1
.ToString(null)) >> (amount
& 63));
2265 throw new InvalidCastException(
2266 Utils
.GetResourceString(
2267 "NoValidOperator_OneOperand",
2268 Utils
.VBFriendlyName(o1
)));
2272 internal static Type
TypeFromTypeCode(TypeCode vartype
) {
2273 return TypeFromTypeCode((int)vartype
);
2276 internal static Type
TypeFromTypeCode(int vartype
) {
2277 return tblTypeFromTypeCode
[vartype
];
2280 public static object XorObj(object obj1
, object obj2
) {
2281 if (obj1
== null && obj2
== null)
2283 TypeCode tc1
= getTypeCode(obj1
);
2284 TypeCode tc2
= getTypeCode(obj2
);
2285 TypeCode widestType
= GetWidestType(tc1
, tc2
);
2286 if (widestType
== TypeCode
.Boolean
|| widestType
== TypeCode
.Byte
2287 || widestType
== TypeCode
.Int16
|| widestType
== TypeCode
.Int32
2288 || widestType
== TypeCode
.Int64
|| widestType
== TypeCode
.Single
2289 || widestType
== TypeCode
.Double
|| widestType
== TypeCode
.Decimal
2290 || widestType
== TypeCode
.String
) {
2291 bool b1
= BooleanType
.FromObject(obj1
);
2292 bool b2
= BooleanType
.FromObject(obj2
);
2293 return (bool)(b1 ^ b2
);
2296 throw new InvalidCastException(
2297 Utils
.GetResourceString(
2298 "NoValidOperator_TwoOperands",
2299 Utils
.VBFriendlyName(obj1
),
2300 Utils
.VBFriendlyName(obj2
)));
2303 // static class VType extends Enum implements IClrInt
2305 // public int value__;
2307 // public static final int t_bad = 0;
2308 // public static final VType _t_bad = new VType(0);
2310 // public static final int t_bool = 1;
2311 // public static final VType _t_bool = new VType(1);
2313 // public static final int t_ui1 = 2;
2314 // public static final VType _t_ui1 = new VType(2);
2316 // public static final int t_i2 = 3;
2317 // public static final VType _t_i2 = new VType(3);
2319 // public static final int t_i4 = 4;
2320 // public static final VType _t_i4 = new VType(4);
2322 // public static final int t_i8 = 5;
2323 // public static final VType _t_i8 = new VType(5);
2325 // public static final int t_dec = 6;
2326 // public static final VType _t_dec = new VType(6);
2328 // public static final int t_r4 = 7;
2329 // public static final VType _t_r4 = new VType(7);
2331 // public static final int t_r8 = 8;
2332 // public static final VType _t_r8 = new VType(8);
2334 // public static final int t_char = 9;
2335 // public static final VType _t_char = new VType(9);
2337 // public static final int t_str = 10;
2338 // public static final VType _t_str = new VType(10);
2340 // public static final int t_date = 11;
2341 // public static final VType _t_date = new VType(11);
2346 // private VType(int value)
2351 // public void __ZeroInit__()
2356 // public void __RealCtor__()
2361 // public VType __Clone__()
2363 // return new VType(value__);
2367 // public int getValue()
2372 // public void setValue(int value)
2377 // public static VType getEnumForValue(int value)
2381 // case t_bad: return _t_bad;
2382 // case t_bool: return _t_bool;
2383 // case t_ui1: return _t_ui1;
2384 // case t_i2: return _t_i2;
2385 // case t_i4: return _t_i4;
2386 // case t_i8: return _t_i8;
2387 // case t_dec: return _t_dec;
2388 // case t_r4: return _t_r4;
2389 // case t_r8: return _t_r8;
2390 // case t_char: return _t_char;
2391 // case t_str: return _t_str;
2392 // case t_date: return _t_date;
2395 // throw new IllegalArgumentException("The value " + value + " is not" +
2396 // " valid for enumeration VType");
2399 // protected object GetValue()
2401 // return new system.ClrInt32(getValue());
2405 // static class VType2 extends Enum implements IClrInt
2407 // public int value__;
2409 // public static final int t_bad = 0;
2410 // public static final VType2 _t_bad = new VType2(0);
2412 // public static final int t_bool = 1;
2413 // public static final VType2 _t_bool = new VType2(1);
2415 // public static final int t_ui1 = 2;
2416 // public static final VType2 _t_ui1 = new VType2(2);
2418 // public static final int t_char = 3;
2419 // public static final VType2 _t_char = new VType2(3);
2421 // public static final int t_i2 = 4;
2422 // public static final VType2 _t_i2 = new VType2(4);
2424 // public static final int t_i4 = 5;
2425 // public static final VType2 _t_i4 = new VType2(5);
2427 // public static final int t_i8 = 6;
2428 // public static final VType2 _t_i8 = new VType2(6);
2430 // public static final int t_r4 = 7;
2431 // public static final VType2 _t_r4 = new VType2(7);
2433 // public static final int t_r8 = 8;
2434 // public static final VType2 _t_r8 = new VType2(8);
2436 // public static final int t_date = 9;
2437 // public static final VType2 _t_date = new VType2(9);
2439 // public static final int t_dec = 10;
2440 // public static final VType2 _t_dec = new VType2(10);
2442 // public static final int t_ref = 11;
2443 // public static final VType2 _t_ref = new VType2(11);
2445 // public static final int t_str = 12;
2446 // public static final VType2 _t_str = new VType2(12);
2451 // private VType2(int value)
2456 // public void __ZeroInit__()
2461 // public void __RealCtor__()
2466 // public VType2 __Clone__()
2468 // return new VType2(value__);
2472 // public int getValue()
2477 // public void setValue(int value)
2482 // public static VType2 getEnumForValue(int value)
2486 // case t_bad: return _t_bad;
2487 // case t_bool: return _t_bool;
2488 // case t_ui1: return _t_ui1;
2489 // case t_char: return _t_char;
2490 // case t_i2: return _t_i2;
2491 // case t_i4: return _t_i4;
2492 // case t_i8: return _t_i8;
2493 // case t_r4: return _t_r4;
2494 // case t_r8: return _t_r8;
2495 // case t_date: return _t_date;
2496 // case t_dec: return _t_dec;
2497 // case t_ref: return _t_ref;
2498 // case t_str: return _t_str;
2501 // throw new IllegalArgumentException("The value " + value + " is not" +
2502 // " valid for enumeration VType2");
2505 // protected object GetValue()
2507 // return new system.ClrInt32(getValue());
2511 // static class CC extends Enum implements IClrInt
2513 // public int value__;
2515 // public static final int Err = 0;
2516 // public static final CC _Err = new CC(0);
2518 // public static final int Same = 1;
2519 // public static final CC _Same = new CC(1);
2521 // public static final int Narr = 2;
2522 // public static final CC _Narr = new CC(2);
2524 // public static final int Wide = 3;
2525 // public static final CC _Wide = new CC(3);
2530 // private CC(int value)
2535 // public void __ZeroInit__()
2540 // public void __RealCtor__()
2545 // public CC __Clone__()
2547 // return new CC(value__);
2550 // public int getValue()
2555 // public void setValue(int value)
2560 // public static CC getEnumForValue(int value)
2564 // case Err: return _Err;
2565 // case Same: return _Same;
2566 // case Narr: return _Narr;
2567 // case Wide: return _Wide;
2570 // throw new IllegalArgumentException("The value " + value + " is not" +
2571 // " valid for enumeration CC");
2574 // protected object GetValue()
2576 // return new system.ClrInt32(getValue());