@@ -211,18 +211,7 @@ internal static unsafe PyType CreateType(Type impl)
211211
212212 static PyType CreateClass ( Type clrType )
213213 {
214- // Cleanup the type name to get rid of funny nested type names.
215- string name = $ "clr.{ clrType . FullName } ";
216- int i = name . LastIndexOf ( '+' ) ;
217- if ( i > - 1 )
218- {
219- name = name . Substring ( i + 1 ) ;
220- }
221- i = name . LastIndexOf ( '.' ) ;
222- if ( i > - 1 )
223- {
224- name = name . Substring ( i + 1 ) ;
225- }
214+ string name = GetPythonTypeName ( clrType ) ;
226215
227216 using var baseTuple = GetBaseTypeTuple ( clrType ) ;
228217
@@ -251,6 +240,65 @@ static PyType CreateClass(Type clrType)
251240 return pyType ;
252241 }
253242
243+ static string GetPythonTypeName ( Type clrType )
244+ {
245+ var result = new System . Text . StringBuilder ( ) ;
246+ GetPythonTypeName ( clrType , target : result ) ;
247+ return result . ToString ( ) ;
248+ }
249+
250+ static void GetPythonTypeName ( Type clrType , System . Text . StringBuilder target )
251+ {
252+ if ( clrType . IsGenericType )
253+ {
254+ string fullName = clrType . GetGenericTypeDefinition ( ) . FullName ;
255+ int argCountIndex = fullName . LastIndexOf ( '`' ) ;
256+ if ( argCountIndex >= 0 )
257+ {
258+ string nonGenericFullName = fullName . Substring ( 0 , argCountIndex ) ;
259+ string nonGenericName = CleanupFullName ( nonGenericFullName ) ;
260+ target . Append ( nonGenericName ) ;
261+
262+ var arguments = clrType . GetGenericArguments ( ) ;
263+ target . Append ( '[' ) ;
264+ for ( int argIndex = 0 ; argIndex < arguments . Length ; argIndex ++ )
265+ {
266+ if ( argIndex != 0 )
267+ {
268+ target . Append ( ',' ) ;
269+ }
270+
271+ GetPythonTypeName ( arguments [ argIndex ] , target ) ;
272+ }
273+
274+ target . Append ( ']' ) ;
275+ return ;
276+ }
277+ }
278+
279+ string name = CleanupFullName ( clrType . FullName ) ;
280+ target . Append ( name ) ;
281+ }
282+
283+ static string CleanupFullName ( string fullTypeName )
284+ {
285+ // Cleanup the type name to get rid of funny nested type names.
286+ string name = "clr." + fullTypeName ;
287+ int i = name . LastIndexOf ( '+' ) ;
288+ if ( i > - 1 )
289+ {
290+ name = name . Substring ( i + 1 ) ;
291+ }
292+
293+ i = name . LastIndexOf ( '.' ) ;
294+ if ( i > - 1 )
295+ {
296+ name = name . Substring ( i + 1 ) ;
297+ }
298+
299+ return name ;
300+ }
301+
254302 static BorrowedReference InitializeBases ( PyType pyType , PyTuple baseTuple )
255303 {
256304 Debug . Assert ( baseTuple . Length ( ) > 0 ) ;
0 commit comments