@@ -52,8 +52,8 @@ static Converter()
5252 /// </summary>
5353 internal static Type GetTypeByAlias ( IntPtr op )
5454 {
55- if ( ( op == Runtime . PyStringType ) ||
56- ( op == Runtime . PyUnicodeType ) )
55+ if ( op == Runtime . PyStringType ||
56+ op == Runtime . PyUnicodeType )
5757 {
5858 return stringType ;
5959 }
@@ -83,24 +83,24 @@ internal static IntPtr GetPythonTypeByAlias(Type op)
8383 return Runtime . PyUnicodeType ;
8484 }
8585
86- else if ( Runtime . IsPython3 && ( ( op == int16Type ) ||
87- ( op == int32Type ) ||
88- ( op == int64Type ) ) )
86+ else if ( Runtime . IsPython3 && ( op == int16Type ||
87+ op == int32Type ||
88+ op == int64Type ) )
8989 {
9090 return Runtime . PyIntType ;
9191 }
9292
93- else if ( ( op == int16Type ) ||
94- ( op == int32Type ) )
93+ else if ( op == int16Type ||
94+ op == int32Type )
9595 {
9696 return Runtime . PyIntType ;
9797 }
9898 else if ( op == int64Type )
9999 {
100100 return Runtime . PyLongType ;
101101 }
102- else if ( ( op == doubleType ) ||
103- ( op == singleType ) )
102+ else if ( op == doubleType ||
103+ op == singleType )
104104 {
105105 return Runtime . PyFloatType ;
106106 }
@@ -123,7 +123,7 @@ internal static IntPtr ToPython<T>(T value)
123123 return ToPython ( value , typeof ( T ) ) ;
124124 }
125125
126- internal static IntPtr ToPython ( Object value , Type type )
126+ internal static IntPtr ToPython ( object value , Type type )
127127 {
128128 if ( value is PyObject )
129129 {
@@ -144,7 +144,7 @@ internal static IntPtr ToPython(Object value, Type type)
144144
145145 // it the type is a python subclass of a managed type then return the
146146 // underlying python object rather than construct a new wrapper object.
147- IPythonDerivedType pyderived = value as IPythonDerivedType ;
147+ var pyderived = value as IPythonDerivedType ;
148148 if ( null != pyderived )
149149 {
150150 return ClassDerivedObject . ToPython ( pyderived ) ;
@@ -221,7 +221,9 @@ internal static IntPtr ToPython(Object value, Type type)
221221 foreach ( object o in ( IEnumerable ) value )
222222 {
223223 using ( var p = new PyObject ( ToPython ( o , o ? . GetType ( ) ) ) )
224+ {
224225 resultlist . Append ( p ) ;
226+ }
225227 }
226228 Runtime . XIncref ( resultlist . Handle ) ;
227229 return resultlist . Handle ;
@@ -237,7 +239,7 @@ internal static IntPtr ToPython(Object value, Type type)
237239 /// In a few situations, we don't have any advisory type information
238240 /// when we want to convert an object to Python.
239241 /// </summary>
240- internal static IntPtr ToPythonImplicit ( Object value )
242+ internal static IntPtr ToPythonImplicit ( object value )
241243 {
242244 if ( value == null )
243245 {
@@ -266,7 +268,7 @@ internal static bool ToManaged(IntPtr value, Type type,
266268
267269
268270 internal static bool ToManagedValue ( IntPtr value , Type obType ,
269- out Object result , bool setError )
271+ out object result , bool setError )
270272 {
271273 if ( obType == typeof ( PyObject ) )
272274 {
@@ -290,8 +292,8 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
290292 result = tmp ;
291293 return true ;
292294 }
293- string err = "value cannot be converted to {0}" ;
294- err = String . Format ( err , obType ) ;
295+ var err = "value cannot be converted to {0}" ;
296+ err = string . Format ( err , obType ) ;
295297 Exceptions . SetError ( Exceptions . TypeError , err ) ;
296298 return false ;
297299 }
@@ -474,7 +476,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
474476 }
475477 long ll = ( long ) Runtime . PyLong_AsLongLong ( op ) ;
476478 Runtime . XDecref ( op ) ;
477- if ( ( ll == - 1 ) && Exceptions . ErrorOccurred ( ) )
479+ if ( ll == - 1 && Exceptions . ErrorOccurred ( ) )
478480 {
479481 goto overflow ;
480482 }
@@ -487,7 +489,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
487489 }
488490
489491 case TypeCode . Boolean :
490- result = ( Runtime . PyObject_IsTrue ( value ) != 0 ) ;
492+ result = Runtime . PyObject_IsTrue ( value ) != 0 ;
491493 return true ;
492494
493495 case TypeCode . Byte :
@@ -791,9 +793,9 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
791793
792794 if ( setError )
793795 {
794- string format = "'{0}' value cannot be converted to {1}" ;
796+ var format = "'{0}' value cannot be converted to {1}" ;
795797 string tpName = Runtime . PyObject_GetTypeName ( value ) ;
796- string error = String . Format ( format , tpName , obType ) ;
798+ string error = string . Format ( format , tpName , obType ) ;
797799 Exceptions . SetError ( Exceptions . TypeError , error ) ;
798800 }
799801
@@ -803,20 +805,20 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
803805
804806 if ( setError )
805807 {
806- string error = "value too large to convert" ;
808+ var error = "value too large to convert" ;
807809 Exceptions . SetError ( Exceptions . OverflowError , error ) ;
808810 }
809811
810812 return false ;
811813 }
812814
813815
814- static void SetConversionError ( IntPtr value , Type target )
816+ private static void SetConversionError ( IntPtr value , Type target )
815817 {
816818 IntPtr ob = Runtime . PyObject_Repr ( value ) ;
817819 string src = Runtime . GetManagedString ( ob ) ;
818820 Runtime . XDecref ( ob ) ;
819- string error = String . Format ( "Cannot convert {0} to {1}" , src , target ) ;
821+ string error = string . Format ( "Cannot convert {0} to {1}" , src , target ) ;
820822 Exceptions . SetError ( Exceptions . TypeError , error ) ;
821823 }
822824
@@ -844,9 +846,9 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s
844846 Array items = Array . CreateInstance ( elementType , size ) ;
845847
846848 // XXX - is there a better way to unwrap this if it is a real array?
847- for ( int i = 0 ; i < size ; i ++ )
849+ for ( var i = 0 ; i < size ; i ++ )
848850 {
849- Object obj = null ;
851+ object obj = null ;
850852 IntPtr item = Runtime . PySequence_GetItem ( value , i ) ;
851853 if ( item == IntPtr . Zero )
852854 {
@@ -899,7 +901,7 @@ private static bool ToEnum(IntPtr value, Type obType, out object result, bool se
899901
900902 if ( setError )
901903 {
902- string error = "invalid enumeration value" ;
904+ var error = "invalid enumeration value" ;
903905 Exceptions . SetError ( Exceptions . ValueError , error ) ;
904906 }
905907
0 commit comments