@@ -18,11 +18,14 @@ internal class AssemblyManager
18
18
// modified from event handlers below, potentially triggered from different .NET threads
19
19
// therefore this should be a ConcurrentDictionary
20
20
static ConcurrentDictionary < string , ConcurrentDictionary < Assembly , string > > namespaces ;
21
+
21
22
//static Dictionary<string, Dictionary<string, string>> generics;
22
23
static AssemblyLoadEventHandler lhandler ;
23
24
static ResolveEventHandler rhandler ;
25
+
24
26
// updated only under GIL?
25
27
static Dictionary < string , int > probed ;
28
+
26
29
// modified from event handlers below, potentially triggered from different .NET threads
27
30
static AssemblyList assemblies ;
28
31
internal static List < string > pypath ;
@@ -47,14 +50,14 @@ internal static void Initialize()
47
50
48
51
AppDomain domain = AppDomain . CurrentDomain ;
49
52
50
- lhandler = new AssemblyLoadEventHandler ( AssemblyLoadHandler ) ;
53
+ lhandler = AssemblyLoadHandler ;
51
54
domain . AssemblyLoad += lhandler ;
52
55
53
- rhandler = new ResolveEventHandler ( ResolveHandler ) ;
56
+ rhandler = ResolveHandler ;
54
57
domain . AssemblyResolve += rhandler ;
55
58
56
59
Assembly [ ] items = domain . GetAssemblies ( ) ;
57
- foreach ( var a in items )
60
+ foreach ( Assembly a in items )
58
61
{
59
62
try
60
63
{
@@ -63,7 +66,7 @@ internal static void Initialize()
63
66
}
64
67
catch ( Exception ex )
65
68
{
66
- Debug . WriteLine ( string . Format ( "Error scanning assembly {0}. {1}" , a , ex ) ) ;
69
+ Debug . WriteLine ( "Error scanning assembly {0}. {1}" , a , ex ) ;
67
70
}
68
71
}
69
72
}
@@ -89,7 +92,7 @@ internal static void Shutdown()
89
92
// Python runtime is initialized.
90
93
//===================================================================
91
94
92
- static void AssemblyLoadHandler ( Object ob , AssemblyLoadEventArgs args )
95
+ private static void AssemblyLoadHandler ( object ob , AssemblyLoadEventArgs args )
93
96
{
94
97
Assembly assembly = args . LoadedAssembly ;
95
98
assemblies . Add ( assembly ) ;
@@ -105,7 +108,7 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args)
105
108
// we loaded from Python which also needs to be found on PYTHONPATH.
106
109
//===================================================================
107
110
108
- static Assembly ResolveHandler ( Object ob , ResolveEventArgs args )
111
+ private static Assembly ResolveHandler ( object ob , ResolveEventArgs args )
109
112
{
110
113
string name = args . Name . ToLower ( ) ;
111
114
foreach ( Assembly a in assemblies )
@@ -205,7 +208,7 @@ public static Assembly LoadAssembly(string name)
205
208
{
206
209
assembly = Assembly . Load ( name ) ;
207
210
}
208
- catch ( System . Exception )
211
+ catch ( Exception )
209
212
{
210
213
//if (!(e is System.IO.FileNotFoundException))
211
214
//{
@@ -230,7 +233,7 @@ public static Assembly LoadAssemblyPath(string name)
230
233
{
231
234
assembly = Assembly . LoadFrom ( path ) ;
232
235
}
233
- catch
236
+ catch ( Exception )
234
237
{
235
238
}
236
239
}
@@ -248,7 +251,9 @@ public static Assembly LoadAssemblyFullPath(string name)
248
251
if ( Path . IsPathRooted ( name ) )
249
252
{
250
253
if ( ! Path . HasExtension ( name ) )
254
+ {
251
255
name = name + ".dll" ;
256
+ }
252
257
if ( File . Exists ( name ) )
253
258
{
254
259
try
@@ -294,13 +299,13 @@ public static Assembly FindLoadedAssembly(string name)
294
299
public static bool LoadImplicit ( string name , bool warn = true )
295
300
{
296
301
string [ ] names = name . Split ( '.' ) ;
297
- bool loaded = false ;
298
- string s = "" ;
302
+ var loaded = false ;
303
+ var s = "" ;
299
304
Assembly lastAssembly = null ;
300
305
HashSet < Assembly > assembliesSet = null ;
301
- for ( int i = 0 ; i < names . Length ; i ++ )
306
+ for ( var i = 0 ; i < names . Length ; i ++ )
302
307
{
303
- s = ( i == 0 ) ? names [ 0 ] : s + "." + names [ i ] ;
308
+ s = i == 0 ? names [ 0 ] : s + "." + names [ i ] ;
304
309
if ( ! probed . ContainsKey ( s ) )
305
310
{
306
311
if ( assembliesSet == null )
@@ -328,7 +333,7 @@ public static bool LoadImplicit(string name, bool warn = true)
328
333
// Deprecation warning
329
334
if ( warn && loaded )
330
335
{
331
- string deprWarning = String . Format (
336
+ string deprWarning = string . Format (
332
337
"\n The module was found, but not in a referenced namespace.\n " +
333
338
"Implicit loading is deprecated. Please use clr.AddReference(\" {0}\" )." ,
334
339
Path . GetFileNameWithoutExtension ( lastAssembly . Location ) ) ;
@@ -353,17 +358,16 @@ internal static void ScanAssembly(Assembly assembly)
353
358
// the assembly.
354
359
355
360
Type [ ] types = assembly . GetTypes ( ) ;
356
- for ( int i = 0 ; i < types . Length ; i ++ )
361
+ foreach ( Type t in types )
357
362
{
358
- Type t = types [ i ] ;
359
363
string ns = t . Namespace ?? "" ;
360
364
if ( ! namespaces . ContainsKey ( ns ) )
361
365
{
362
366
string [ ] names = ns . Split ( '.' ) ;
363
- string s = "" ;
364
- for ( int n = 0 ; n < names . Length ; n ++ )
367
+ var s = "" ;
368
+ for ( var n = 0 ; n < names . Length ; n ++ )
365
369
{
366
- s = ( n == 0 ) ? names [ 0 ] : s + "." + names [ n ] ;
370
+ s = n == 0 ? names [ 0 ] : s + "." + names [ n ] ;
367
371
namespaces . TryAdd ( s , new ConcurrentDictionary < Assembly , string > ( ) ) ;
368
372
}
369
373
}
@@ -382,7 +386,7 @@ internal static void ScanAssembly(Assembly assembly)
382
386
383
387
public static AssemblyName [ ] ListAssemblies ( )
384
388
{
385
- List < AssemblyName > names = new List < AssemblyName > ( assemblies . Count ) ;
389
+ var names = new List < AssemblyName > ( assemblies . Count ) ;
386
390
foreach ( Assembly assembly in assemblies )
387
391
{
388
392
names . Add ( assembly . GetName ( ) ) ;
@@ -397,7 +401,7 @@ public static AssemblyName[] ListAssemblies()
397
401
398
402
public static bool IsValidNamespace ( string name )
399
403
{
400
- return ! String . IsNullOrEmpty ( name ) && namespaces . ContainsKey ( name ) ;
404
+ return ! string . IsNullOrEmpty ( name ) && namespaces . ContainsKey ( name ) ;
401
405
}
402
406
403
407
//===================================================================
@@ -406,10 +410,7 @@ public static bool IsValidNamespace(string name)
406
410
407
411
public static IEnumerable < Assembly > GetAssemblies ( string nsname )
408
412
{
409
- if ( ! namespaces . ContainsKey ( nsname ) )
410
- return new List < Assembly > ( ) ;
411
-
412
- return namespaces [ nsname ] . Keys ;
413
+ return ! namespaces . ContainsKey ( nsname ) ? new List < Assembly > ( ) : namespaces [ nsname ] . Keys ;
413
414
}
414
415
415
416
//===================================================================
@@ -419,7 +420,7 @@ public static IEnumerable<Assembly> GetAssemblies(string nsname)
419
420
public static List < string > GetNames ( string nsname )
420
421
{
421
422
//Dictionary<string, int> seen = new Dictionary<string, int>();
422
- List < string > names = new List < string > ( 8 ) ;
423
+ var names = new List < string > ( 8 ) ;
423
424
424
425
List < string > g = GenericUtil . GetGenericBaseNames ( nsname ) ;
425
426
if ( g != null )
@@ -435,9 +436,8 @@ public static List<string> GetNames(string nsname)
435
436
foreach ( Assembly a in namespaces [ nsname ] . Keys )
436
437
{
437
438
Type [ ] types = a . GetTypes ( ) ;
438
- for ( int i = 0 ; i < types . Length ; i ++ )
439
+ foreach ( Type t in types )
439
440
{
440
- Type t = types [ i ] ;
441
441
if ( ( t . Namespace ?? "" ) == nsname )
442
442
{
443
443
names . Add ( t . Name ) ;
0 commit comments