1
1
using System ;
2
+ using System . Collections ;
3
+ using System . Globalization ;
2
4
using System . Reflection ;
3
5
using System . Runtime . InteropServices ;
4
- using System . Globalization ;
5
6
using System . Security ;
6
- using System . Collections ;
7
7
8
8
namespace Python . Runtime
9
9
{
@@ -292,9 +292,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
292
292
result = tmp ;
293
293
return true ;
294
294
}
295
- var err = "value cannot be converted to {0}" ;
296
- err = string . Format ( err , obType ) ;
297
- Exceptions . SetError ( Exceptions . TypeError , err ) ;
295
+ Exceptions . SetError ( Exceptions . TypeError , $ "value cannot be converted to { obType } ") ;
298
296
return false ;
299
297
}
300
298
if ( mt is ClassBase )
@@ -793,10 +791,8 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
793
791
794
792
if ( setError )
795
793
{
796
- var format = "'{0}' value cannot be converted to {1}" ;
797
794
string tpName = Runtime . PyObject_GetTypeName ( value ) ;
798
- string error = string . Format ( format , tpName , obType ) ;
799
- Exceptions . SetError ( Exceptions . TypeError , error ) ;
795
+ Exceptions . SetError ( Exceptions . TypeError , $ "'{ tpName } ' value cannot be converted to { obType } ") ;
800
796
}
801
797
802
798
return false ;
@@ -805,8 +801,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
805
801
806
802
if ( setError )
807
803
{
808
- var error = "value too large to convert" ;
809
- Exceptions . SetError ( Exceptions . OverflowError , error ) ;
804
+ Exceptions . SetError ( Exceptions . OverflowError , "value too large to convert" ) ;
810
805
}
811
806
812
807
return false ;
@@ -818,8 +813,7 @@ private static void SetConversionError(IntPtr value, Type target)
818
813
IntPtr ob = Runtime . PyObject_Repr ( value ) ;
819
814
string src = Runtime . GetManagedString ( ob ) ;
820
815
Runtime . XDecref ( ob ) ;
821
- string error = string . Format ( "Cannot convert {0} to {1}" , src , target ) ;
822
- Exceptions . SetError ( Exceptions . TypeError , error ) ;
816
+ Exceptions . SetError ( Exceptions . TypeError , $ "Cannot convert { src } to { target } ") ;
823
817
}
824
818
825
819
@@ -901,8 +895,7 @@ private static bool ToEnum(IntPtr value, Type obType, out object result, bool se
901
895
902
896
if ( setError )
903
897
{
904
- var error = "invalid enumeration value" ;
905
- Exceptions . SetError ( Exceptions . ValueError , error ) ;
898
+ Exceptions . SetError ( Exceptions . ValueError , "invalid enumeration value" ) ;
906
899
}
907
900
908
901
return false ;
0 commit comments