4 // (C) 2008 Mainsoft, Inc. (http://www.mainsoft.com)
5 // (C) 2008 db4objects, Inc. (http://www.db4o.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 namespace System
.Linq
.jvm
{
33 public static object ConvertPrimitiveUnChecked (Type
from, Type to
, object value)
36 switch (Type
.GetTypeCode (from)) {
38 return ConvertByte ((byte) value, to
);
40 return ConvertChar ((char) value, to
);
41 case TypeCode
.Decimal
:
42 return ConvertDecimal ((decimal) value, to
);
44 return ConvertDouble ((double) value, to
);
46 return ConvertShort ((short) value, to
);
48 return ConvertInt ((int) value, to
);
50 return ConvertLong ((long) value, to
);
52 return ConvertSByte ((sbyte) value, to
);
54 return ConvertFloat ((float) value, to
);
56 return ConvertUShort ((ushort) value, to
);
58 return ConvertUInt ((uint) value, to
);
60 return ConvertULong ((ulong) value, to
);
62 throw new NotImplementedException ();
67 static object ConvertByte (byte b
, Type to
)
70 switch (Type
.GetTypeCode (to
)) {
75 case TypeCode
.Decimal
:
100 static object ConvertChar (char b
, Type to
)
103 switch (Type
.GetTypeCode (to
)) {
108 case TypeCode
.Decimal
:
110 case TypeCode
.Double
:
120 case TypeCode
.Single
:
122 case TypeCode
.UInt16
:
124 case TypeCode
.UInt32
:
126 case TypeCode
.UInt64
:
133 static object ConvertDecimal (decimal b
, Type to
)
136 switch (Type
.GetTypeCode (to
)) {
140 return (char) (short) b
;
141 case TypeCode
.Decimal
:
143 case TypeCode
.Double
:
153 case TypeCode
.Single
:
155 case TypeCode
.UInt16
:
157 case TypeCode
.UInt32
:
159 case TypeCode
.UInt64
:
166 static object ConvertDouble (double b
, Type to
)
169 switch (Type
.GetTypeCode (to
)) {
174 case TypeCode
.Decimal
:
176 case TypeCode
.Double
:
186 case TypeCode
.Single
:
188 case TypeCode
.UInt16
:
190 case TypeCode
.UInt32
:
192 case TypeCode
.UInt64
:
199 static object ConvertShort (short b
, Type to
)
202 switch (Type
.GetTypeCode (to
)) {
207 case TypeCode
.Decimal
:
209 case TypeCode
.Double
:
219 case TypeCode
.Single
:
221 case TypeCode
.UInt16
:
223 case TypeCode
.UInt32
:
225 case TypeCode
.UInt64
:
232 static object ConvertInt (int b
, Type to
)
235 switch (Type
.GetTypeCode (to
)) {
240 case TypeCode
.Decimal
:
242 case TypeCode
.Double
:
252 case TypeCode
.Single
:
254 case TypeCode
.UInt16
:
256 case TypeCode
.UInt32
:
258 case TypeCode
.UInt64
:
265 static object ConvertLong (long b
, Type to
)
268 switch (Type
.GetTypeCode (to
)) {
273 case TypeCode
.Decimal
:
275 case TypeCode
.Double
:
285 case TypeCode
.Single
:
287 case TypeCode
.UInt16
:
289 case TypeCode
.UInt32
:
291 case TypeCode
.UInt64
:
298 static object ConvertSByte (sbyte b
, Type to
)
301 switch (Type
.GetTypeCode (to
)) {
306 case TypeCode
.Decimal
:
308 case TypeCode
.Double
:
318 case TypeCode
.Single
:
320 case TypeCode
.UInt16
:
322 case TypeCode
.UInt32
:
324 case TypeCode
.UInt64
:
331 static object ConvertFloat (float b
, Type to
)
334 switch (Type
.GetTypeCode (to
)) {
339 case TypeCode
.Decimal
:
341 case TypeCode
.Double
:
351 case TypeCode
.Single
:
353 case TypeCode
.UInt16
:
355 case TypeCode
.UInt32
:
357 case TypeCode
.UInt64
:
364 static object ConvertUShort (ushort b
, Type to
)
367 switch (Type
.GetTypeCode (to
)) {
372 case TypeCode
.Decimal
:
374 case TypeCode
.Double
:
384 case TypeCode
.Single
:
386 case TypeCode
.UInt16
:
388 case TypeCode
.UInt32
:
390 case TypeCode
.UInt64
:
397 static object ConvertUInt (uint b
, Type to
)
400 switch (Type
.GetTypeCode (to
)) {
405 case TypeCode
.Decimal
:
407 case TypeCode
.Double
:
417 case TypeCode
.Single
:
419 case TypeCode
.UInt16
:
421 case TypeCode
.UInt32
:
423 case TypeCode
.UInt64
:
430 static object ConvertULong (ulong b
, Type to
)
433 switch (Type
.GetTypeCode (to
)) {
438 case TypeCode
.Decimal
:
440 case TypeCode
.Double
:
450 case TypeCode
.Single
:
452 case TypeCode
.UInt16
:
454 case TypeCode
.UInt32
:
456 case TypeCode
.UInt64
: