@@ -24,10 +24,10 @@ namespace Python.Runtime {
2424
2525 internal class AssemblyManager {
2626
27+ static Dictionary < string , Dictionary < Assembly , string > > namespaces ;
28+ static Dictionary < string , Dictionary < string , string > > generics ;
2729 static AssemblyLoadEventHandler lhandler ;
2830 static ResolveEventHandler rhandler ;
29- static Dictionary < string , string > snames ;
30- static Dictionary < string , Dictionary < Assembly , string > > namespaces ;
3131 static Dictionary < string , int > probed ;
3232 static List < Assembly > assemblies ;
3333 static List < string > pypath ;
@@ -42,11 +42,10 @@ private AssemblyManager() {}
4242 //===================================================================
4343
4444 internal static void Initialize ( ) {
45- snames = new Dictionary < string , string > ( ) ;
46-
4745 namespaces = new
4846 Dictionary < string , Dictionary < Assembly , string > > ( 32 ) ;
4947 probed = new Dictionary < string , int > ( 32 ) ;
48+ generics = new Dictionary < string , Dictionary < string , string > > ( ) ;
5049 assemblies = new List < Assembly > ( 16 ) ;
5150 pypath = new List < string > ( 16 ) ;
5251
@@ -114,32 +113,6 @@ static Assembly ResolveHandler(Object ob, ResolveEventArgs args){
114113 }
115114
116115
117- //===================================================================
118- // Certain kinds of names (such as the names of generic types) are
119- // mangled so we need to perform mapping from human-friendly names
120- // to inhumane names. Given a friendly name, this method will either
121- // return the associated inhumane name or the original name with no
122- // changes if there is no mapping for that name.
123- //===================================================================
124-
125- static string ConvertSpecialName ( string name ) {
126- if ( snames . ContainsKey ( name ) ) {
127- return snames [ name ] ;
128- }
129- return name ;
130- }
131-
132- static void AddSpecialName ( string nice , string ugly ) {
133- if ( ! snames . ContainsKey ( nice ) ) {
134- snames . Add ( nice , ugly ) ;
135- }
136- else {
137- //Console.WriteLine("dup: {0} : {1}", nice, ugly);
138- }
139-
140- }
141-
142-
143116 //===================================================================
144117 // We __really__ want to avoid using Python objects or APIs when
145118 // probing for assemblies to load, since our ResolveHandler may be
@@ -211,7 +184,9 @@ static string FindAssembly(string name) {
211184 public static Assembly LoadAssembly ( string name ) {
212185 Assembly assembly = null ;
213186 try {
187+ #pragma warning disable 618
214188 assembly = Assembly . LoadWithPartialName ( name ) ;
189+ #pragma warning restore 618
215190 }
216191 catch {
217192 }
@@ -272,11 +247,7 @@ static void ScanAssembly(Assembly assembly) {
272247
273248 // A couple of things we want to do here: first, we want to
274249 // gather a list of all of the namespaces contributed to by
275- // the assembly. Since we have to rifle through all of the
276- // types in the assembly anyway, we also build up a running
277- // list of 'odd names' like generic names so that we can map
278- // them appropriately later while still being lazy about
279- // type lookup and instantiation.
250+ // the assembly.
280251
281252 Type [ ] types = assembly . GetTypes ( ) ;
282253 for ( int i = 0 ; i < types . Length ; i ++ ) {
@@ -300,12 +271,35 @@ static void ScanAssembly(Assembly assembly) {
300271 }
301272
302273 if ( t . IsGenericTypeDefinition ) {
303- string qname = t . FullName ;
304- int tick = qname . IndexOf ( '`' ) ;
305- if ( tick != - 1 ) {
306- AddSpecialName ( qname . Substring ( 0 , tick ) , qname ) ;
307- }
274+ GenericManager . Register ( t ) ;
275+ // Dictionary<string, string> map = null;
276+ // generics.TryGetValue(t.Namespace, out map);
277+ // if (map == null) {
278+ // map = new Dictionary<string, string>();
279+ // generics[t.Namespace] = map;
280+ // }
281+ // string bname = t.Name;
282+ // string mapped = null;
283+ // int tick = bname.IndexOf("`");
284+ // if (tick > -1) {
285+ // bname = bname.Substring(0, tick);
286+ // }
287+ // map.TryGetValue(bname, out mapped);
288+ // if (mapped == null) {
289+ // map[bname] = t.Name;
290+ // }
308291 }
292+
293+ // if (t.IsGenericTypeDefinition) {
294+ // List<string> snames = null;
295+ // special.TryGetValue(t.Namespace, out snames);
296+ // if (snames == null) {
297+ // snames = new List<string>(8);
298+ // special[t.Namespace] = snames;
299+ // }
300+ // snames.Add(t.Name);
301+ // }
302+
309303
310304 }
311305 }
@@ -326,16 +320,23 @@ public static bool IsValidNamespace(string name) {
326320 //===================================================================
327321
328322 public static List < string > GetNames ( string nsname ) {
329- List < string > names = new List < string > ( 32 ) ;
330323 Dictionary < string , int > seen = new Dictionary < string , int > ( ) ;
324+ List < string > names = new List < string > ( 8 ) ;
325+
326+ List < string > g = GenericManager . GetGenericBaseNames ( nsname ) ;
327+ if ( g != null ) {
328+ foreach ( string n in g ) {
329+ names . Add ( n ) ;
330+ }
331+ }
331332
332333 if ( namespaces . ContainsKey ( nsname ) ) {
333334 foreach ( Assembly a in namespaces [ nsname ] . Keys ) {
334335 Type [ ] types = a . GetTypes ( ) ;
335336 for ( int i = 0 ; i < types . Length ; i ++ ) {
336337 Type t = types [ i ] ;
337338 if ( t . Namespace == nsname ) {
338- names . Add ( ConvertSpecialName ( t . Name ) ) ;
339+ names . Add ( t . Name ) ;
339340 }
340341 }
341342 }
@@ -349,7 +350,6 @@ public static List<string> GetNames(string nsname) {
349350 }
350351 }
351352 }
352- names . Sort ( ) ; // ensure that non-generics come first!
353353 return names ;
354354 }
355355
@@ -359,13 +359,10 @@ public static List<string> GetNames(string nsname) {
359359 // type. Returns null if the named type cannot be found.
360360 //===================================================================
361361
362- // funny names: generics,
363-
364362 public static Type LookupType ( string qname ) {
365- string name = ConvertSpecialName ( qname ) ;
366363 for ( int i = 0 ; i < assemblies . Count ; i ++ ) {
367364 Assembly assembly = ( Assembly ) assemblies [ i ] ;
368- Type type = assembly . GetType ( name ) ;
365+ Type type = assembly . GetType ( qname ) ;
369366 if ( type != null ) {
370367 return type ;
371368 }
0 commit comments