1- // Copyright (c) 2001, 2002 Zope Corporation and Contributors.
2- //
3- // All Rights Reserved.
4- //
1+ // ==========================================================================
52// This software is subject to the provisions of the Zope Public License,
63// Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
74// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
85// WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
96// WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
107// FOR A PARTICULAR PURPOSE.
8+ // ==========================================================================
119
1210using System ;
1311using System . IO ;
@@ -32,7 +30,6 @@ internal class AssemblyManager {
3230 static Hashtable namespaces ;
3331 static ArrayList assemblies ;
3432 static Hashtable probed ;
35- static int last ;
3633
3734 private AssemblyManager ( ) { }
3835
@@ -241,28 +238,33 @@ public static bool LoadImplicit(string name) {
241238
242239 static void ScanAssembly ( Assembly assembly ) {
243240
244- // TODO: this is a workaround for a current Mono bug: calling
245- // GetTypes on a generated assembly will cause it to fall over.
246- // For now we'll skip generated assemblies, which usually are
247- // uninteresting support code anyway.
248-
249- if ( assembly is AssemblyBuilder ) {
250- return ;
251- }
241+ // A couple of things we want to do here: first, we want to
242+ // gather a list of all of the namespaces contributed to by
243+ // the assembly. Since we have to rifle through all of the
244+ // types in the assembly anyway, we also build up a running
245+ // list of 'odd names' like generic names so that we can map
246+ // them appropriately later while still being lazy about
247+ // type lookup and instantiation.
252248
253249 Type [ ] types = assembly . GetTypes ( ) ;
254250 for ( int i = 0 ; i < types . Length ; i ++ ) {
255- string type_ns = types [ i ] . Namespace ;
256- if ( ( type_ns != null ) && ( ! namespaces . ContainsKey ( type_ns ) ) ) {
257- string [ ] names = type_ns . Split ( '.' ) ;
251+ Type t = types [ i ] ;
252+ string ns = t . Namespace != null ? t . Namespace : "" ;
253+ if ( ( ns != null ) && ( ! namespaces . ContainsKey ( ns ) ) ) {
254+ string [ ] names = ns . Split ( '.' ) ;
258255 string s = "" ;
259256 for ( int n = 0 ; n < names . Length ; n ++ ) {
260257 s = ( n == 0 ) ? names [ 0 ] : s + "." + names [ n ] ;
261258 if ( ! namespaces . ContainsKey ( s ) ) {
262- namespaces . Add ( s , String . Empty ) ;
259+ namespaces . Add ( s , new Hashtable ( ) ) ;
263260 }
264261 }
265262 }
263+
264+ Hashtable asm = namespaces [ ns ] as Hashtable ;
265+ if ( ns != null && ! asm . ContainsKey ( assembly ) ) {
266+ asm . Add ( assembly , String . Empty ) ;
267+ }
266268 }
267269 }
268270
@@ -277,6 +279,38 @@ public static bool IsValidNamespace(string name) {
277279 }
278280
279281
282+ //===================================================================
283+ // Returns the current list of valid names for the input namespace.
284+ //===================================================================
285+
286+ public static StringCollection GetNames ( string nsname ) {
287+ StringCollection names = new StringCollection ( ) ;
288+ if ( namespaces . ContainsKey ( nsname ) ) {
289+ Hashtable asm = namespaces [ nsname ] as Hashtable ;
290+ foreach ( Object o in asm . Keys ) {
291+ Assembly a = o as Assembly ;
292+ Type [ ] types = a . GetTypes ( ) ;
293+ for ( int i = 0 ; i < types . Length ; i ++ ) {
294+ Type t = types [ i ] ;
295+ if ( t . Namespace == nsname ) {
296+ names . Add ( t . Name ) ;
297+ }
298+ }
299+ }
300+ int nslen = nsname . Length ;
301+ foreach ( object n in namespaces . Keys ) {
302+ string key = n as string ;
303+ if ( key . Length > nslen && key . StartsWith ( nsname ) ) {
304+ string tail = key . Substring ( nslen ) ;
305+ if ( key . IndexOf ( '.' ) == - 1 ) {
306+ names . Add ( key ) ;
307+ }
308+ }
309+ }
310+ }
311+ return names ;
312+ }
313+
280314 //===================================================================
281315 // Returns the System.Type object for a given qualified name,
282316 // looking in the currently loaded assemblies for the named
0 commit comments