@@ -52,62 +52,53 @@ static Converter()
52
52
/// </summary>
53
53
internal static Type GetTypeByAlias ( IntPtr op )
54
54
{
55
- if ( op == Runtime . PyStringType ||
56
- op == Runtime . PyUnicodeType )
57
- {
55
+ if ( op == Runtime . PyStringType )
58
56
return stringType ;
59
- }
60
- else if ( op == Runtime . PyIntType )
61
- {
57
+
58
+ if ( op == Runtime . PyUnicodeType )
59
+ return stringType ;
60
+
61
+ if ( op == Runtime . PyIntType )
62
62
return int32Type ;
63
- }
64
- else if ( op == Runtime . PyLongType )
65
- {
63
+
64
+ if ( op == Runtime . PyLongType )
66
65
return int64Type ;
67
- }
68
- else if ( op == Runtime . PyFloatType )
69
- {
66
+
67
+ if ( op == Runtime . PyFloatType )
70
68
return doubleType ;
71
- }
72
- else if ( op == Runtime . PyBoolType )
73
- {
69
+
70
+ if ( op == Runtime . PyBoolType )
74
71
return boolType ;
75
- }
72
+
76
73
return null ;
77
74
}
78
75
79
76
internal static IntPtr GetPythonTypeByAlias ( Type op )
80
77
{
81
78
if ( op == stringType )
82
- {
83
79
return Runtime . PyUnicodeType ;
84
- }
85
80
86
- else if ( Runtime . IsPython3 && ( op == int16Type ||
87
- op == int32Type ||
88
- op == int64Type ) )
89
- {
81
+ if ( op == int16Type )
90
82
return Runtime . PyIntType ;
91
- }
92
83
93
- else if ( op == int16Type ||
94
- op == int32Type )
95
- {
84
+ if ( op == int32Type )
96
85
return Runtime . PyIntType ;
97
- }
98
- else if ( op == int64Type )
99
- {
86
+
87
+ if ( op == int64Type && Runtime . IsPython2 )
100
88
return Runtime . PyLongType ;
101
- }
102
- else if ( op == doubleType ||
103
- op == singleType )
104
- {
89
+
90
+ if ( op == int64Type )
91
+ return Runtime . PyIntType ;
92
+
93
+ if ( op == doubleType )
105
94
return Runtime . PyFloatType ;
106
- }
107
- else if ( op == boolType )
108
- {
95
+
96
+ if ( op == singleType )
97
+ return Runtime . PyFloatType ;
98
+
99
+ if ( op == boolType )
109
100
return Runtime . PyBoolType ;
110
- }
101
+
111
102
return IntPtr . Zero ;
112
103
}
113
104
@@ -329,27 +320,27 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
329
320
return ToPrimitive ( value , stringType , out result , setError ) ;
330
321
}
331
322
332
- else if ( Runtime . PyBool_Check ( value ) )
323
+ if ( Runtime . PyBool_Check ( value ) )
333
324
{
334
325
return ToPrimitive ( value , boolType , out result , setError ) ;
335
326
}
336
327
337
- else if ( Runtime . PyInt_Check ( value ) )
328
+ if ( Runtime . PyInt_Check ( value ) )
338
329
{
339
330
return ToPrimitive ( value , int32Type , out result , setError ) ;
340
331
}
341
332
342
- else if ( Runtime . PyLong_Check ( value ) )
333
+ if ( Runtime . PyLong_Check ( value ) )
343
334
{
344
335
return ToPrimitive ( value , int64Type , out result , setError ) ;
345
336
}
346
337
347
- else if ( Runtime . PyFloat_Check ( value ) )
338
+ if ( Runtime . PyFloat_Check ( value ) )
348
339
{
349
340
return ToPrimitive ( value , doubleType , out result , setError ) ;
350
341
}
351
342
352
- else if ( Runtime . PySequence_Check ( value ) )
343
+ if ( Runtime . PySequence_Check ( value ) )
353
344
{
354
345
return ToArray ( value , typeof ( object [ ] ) , out result , setError ) ;
355
346
}
@@ -371,31 +362,31 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
371
362
return true ;
372
363
}
373
364
374
- else if ( value == Runtime . PyBoolType )
365
+ if ( value == Runtime . PyBoolType )
375
366
{
376
367
result = boolType ;
377
368
return true ;
378
369
}
379
370
380
- else if ( value == Runtime . PyIntType )
371
+ if ( value == Runtime . PyIntType )
381
372
{
382
373
result = int32Type ;
383
374
return true ;
384
375
}
385
376
386
- else if ( value == Runtime . PyLongType )
377
+ if ( value == Runtime . PyLongType )
387
378
{
388
379
result = int64Type ;
389
380
return true ;
390
381
}
391
382
392
- else if ( value == Runtime . PyFloatType )
383
+ if ( value == Runtime . PyFloatType )
393
384
{
394
385
result = doubleType ;
395
386
return true ;
396
387
}
397
388
398
- else if ( value == Runtime . PyListType || value == Runtime . PyTupleType )
389
+ if ( value == Runtime . PyListType || value == Runtime . PyTupleType )
399
390
{
400
391
result = typeof ( object [ ] ) ;
401
392
return true ;
0 commit comments