File tree Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Original file line number Diff line number Diff line change @@ -242,25 +242,18 @@ public static IntPtr tp_str(IntPtr ob)
242
242
243
243
//First check which type in the object hierarchy provides ToString()
244
244
//ToString has two "official" overloads so loop over GetMethods to get the one without parameters
245
- var instType = co . inst . GetType ( ) ;
246
- foreach ( var method in instType . GetMethods ( ) )
247
- {
248
-
249
- //TODO this could probably be done more cleanly with Linq
250
- if ( ! method . IsPublic ) continue ; //skip private/protected methods
251
- if ( method . Name != "ToString" ) continue ; //only look for ToString
252
- if ( method . DeclaringType == typeof ( object ) ) continue ; //ignore default from object
253
- if ( method . GetParameters ( ) . Length != 0 ) continue ; //ignore Formatter overload of ToString
254
-
245
+ var method = type . GetMethod ( "ToString" , new Type [ ] { } ) ;
246
+ if ( method . DeclaringTyppe != typeof ( object ) )
247
+ {
255
248
//match! something other than object provides a parameter-less overload of ToString
256
- return Runtime . PyString_FromString ( co . inst . ToString ( ) ) ;
257
- }
249
+ return Runtime . Pystring_FromString ( co . inst . ToString ( ) ) ;
250
+ }
258
251
259
252
//If the object defines __repr__, call it.
260
253
System . Reflection . MethodInfo reprMethodInfo = instType . GetMethod ( "__repr__" ) ;
261
254
if ( reprMethodInfo != null && reprMethodInfo . IsPublic )
262
255
{
263
- var reprString = reprMethodInfo . Invoke ( co . inst , null ) as string ;
256
+ var reprString = ( string ) reprMethodInfo . Invoke ( co . inst , null ) ;
264
257
return Runtime . PyString_FromString ( reprString ) ;
265
258
}
266
259
You can’t perform that action at this time.
0 commit comments