11using System ;
2+ using System . Collections ;
3+ using System . Globalization ;
24using System . Reflection ;
35using System . Runtime . InteropServices ;
4- using System . Globalization ;
56using System . Security ;
6- using System . Collections ;
77
88namespace Python . Runtime
99{
@@ -292,9 +292,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
292292 result = tmp ;
293293 return true ;
294294 }
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 } ") ;
298296 return false ;
299297 }
300298 if ( mt is ClassBase )
@@ -793,10 +791,8 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
793791
794792 if ( setError )
795793 {
796- var format = "'{0}' value cannot be converted to {1}" ;
797794 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 } ") ;
800796 }
801797
802798 return false ;
@@ -805,8 +801,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
805801
806802 if ( setError )
807803 {
808- var error = "value too large to convert" ;
809- Exceptions . SetError ( Exceptions . OverflowError , error ) ;
804+ Exceptions . SetError ( Exceptions . OverflowError , "value too large to convert" ) ;
810805 }
811806
812807 return false ;
@@ -818,8 +813,7 @@ private static void SetConversionError(IntPtr value, Type target)
818813 IntPtr ob = Runtime . PyObject_Repr ( value ) ;
819814 string src = Runtime . GetManagedString ( ob ) ;
820815 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 } ") ;
823817 }
824818
825819
@@ -901,8 +895,7 @@ private static bool ToEnum(IntPtr value, Type obType, out object result, bool se
901895
902896 if ( setError )
903897 {
904- var error = "invalid enumeration value" ;
905- Exceptions . SetError ( Exceptions . ValueError , error ) ;
898+ Exceptions . SetError ( Exceptions . ValueError , "invalid enumeration value" ) ;
906899 }
907900
908901 return false ;
0 commit comments