@@ -21,8 +21,10 @@ internal class AssemblyManager
21
21
//static Dictionary<string, Dictionary<string, string>> generics;
22
22
static AssemblyLoadEventHandler lhandler ;
23
23
static ResolveEventHandler rhandler ;
24
+
24
25
// updated only under GIL?
25
26
static Dictionary < string , int > probed ;
27
+
26
28
// modified from event handlers below, potentially triggered from different .NET threads
27
29
static AssemblyList assemblies ;
28
30
internal static List < string > pypath ;
@@ -53,7 +55,7 @@ internal static void Initialize()
53
55
domain . AssemblyResolve += rhandler ;
54
56
55
57
Assembly [ ] items = domain . GetAssemblies ( ) ;
56
- foreach ( var a in items )
58
+ foreach ( Assembly a in items )
57
59
{
58
60
try
59
61
{
@@ -62,7 +64,7 @@ internal static void Initialize()
62
64
}
63
65
catch ( Exception ex )
64
66
{
65
- Debug . WriteLine ( string . Format ( "Error scanning assembly {0}. {1}" , a , ex ) ) ;
67
+ Debug . WriteLine ( "Error scanning assembly {0}. {1}" , a , ex ) ;
66
68
}
67
69
}
68
70
}
@@ -86,7 +88,7 @@ internal static void Shutdown()
86
88
/// so that we can know about assemblies that get loaded after the
87
89
/// Python runtime is initialized.
88
90
/// </summary>
89
- static void AssemblyLoadHandler ( Object ob , AssemblyLoadEventArgs args )
91
+ private static void AssemblyLoadHandler ( object ob , AssemblyLoadEventArgs args )
90
92
{
91
93
Assembly assembly = args . LoadedAssembly ;
92
94
assemblies . Add ( assembly ) ;
@@ -101,7 +103,7 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args)
101
103
/// for failed loads, because they might be dependencies of something
102
104
/// we loaded from Python which also needs to be found on PYTHONPATH.
103
105
/// </summary>
104
- static Assembly ResolveHandler ( Object ob , ResolveEventArgs args )
106
+ private static Assembly ResolveHandler ( object ob , ResolveEventArgs args )
105
107
{
106
108
string name = args . Name . ToLower ( ) ;
107
109
foreach ( Assembly a in assemblies )
@@ -197,7 +199,7 @@ public static Assembly LoadAssembly(string name)
197
199
{
198
200
assembly = Assembly . Load ( name ) ;
199
201
}
200
- catch ( System . Exception )
202
+ catch ( Exception )
201
203
{
202
204
//if (!(e is System.IO.FileNotFoundException))
203
205
//{
@@ -221,7 +223,7 @@ public static Assembly LoadAssemblyPath(string name)
221
223
{
222
224
assembly = Assembly . LoadFrom ( path ) ;
223
225
}
224
- catch
226
+ catch ( Exception )
225
227
{
226
228
}
227
229
}
@@ -241,7 +243,9 @@ public static Assembly LoadAssemblyFullPath(string name)
241
243
if ( Path . IsPathRooted ( name ) )
242
244
{
243
245
if ( ! Path . HasExtension ( name ) )
246
+ {
244
247
name = name + ".dll" ;
248
+ }
245
249
if ( File . Exists ( name ) )
246
250
{
247
251
try
@@ -287,13 +291,13 @@ public static Assembly FindLoadedAssembly(string name)
287
291
public static bool LoadImplicit ( string name , bool warn = true )
288
292
{
289
293
string [ ] names = name . Split ( '.' ) ;
290
- bool loaded = false ;
291
- string s = "" ;
294
+ var loaded = false ;
295
+ var s = "" ;
292
296
Assembly lastAssembly = null ;
293
297
HashSet < Assembly > assembliesSet = null ;
294
- for ( int i = 0 ; i < names . Length ; i ++ )
298
+ for ( var i = 0 ; i < names . Length ; i ++ )
295
299
{
296
- s = ( i == 0 ) ? names [ 0 ] : s + "." + names [ i ] ;
300
+ s = i == 0 ? names [ 0 ] : s + "." + names [ i ] ;
297
301
if ( ! probed . ContainsKey ( s ) )
298
302
{
299
303
if ( assembliesSet == null )
@@ -321,7 +325,7 @@ public static bool LoadImplicit(string name, bool warn = true)
321
325
// Deprecation warning
322
326
if ( warn && loaded )
323
327
{
324
- string deprWarning = String . Format (
328
+ string deprWarning = string . Format (
325
329
"\n The module was found, but not in a referenced namespace.\n " +
326
330
"Implicit loading is deprecated. Please use clr.AddReference(\" {0}\" )." ,
327
331
Path . GetFileNameWithoutExtension ( lastAssembly . Location ) ) ;
@@ -345,17 +349,16 @@ internal static void ScanAssembly(Assembly assembly)
345
349
// the assembly.
346
350
347
351
Type [ ] types = assembly . GetTypes ( ) ;
348
- for ( int i = 0 ; i < types . Length ; i ++ )
352
+ foreach ( Type t in types )
349
353
{
350
- Type t = types [ i ] ;
351
354
string ns = t . Namespace ?? "" ;
352
355
if ( ! namespaces . ContainsKey ( ns ) )
353
356
{
354
357
string [ ] names = ns . Split ( '.' ) ;
355
- string s = "" ;
356
- for ( int n = 0 ; n < names . Length ; n ++ )
358
+ var s = "" ;
359
+ for ( var n = 0 ; n < names . Length ; n ++ )
357
360
{
358
- s = ( n == 0 ) ? names [ 0 ] : s + "." + names [ n ] ;
361
+ s = n == 0 ? names [ 0 ] : s + "." + names [ n ] ;
359
362
namespaces . TryAdd ( s , new ConcurrentDictionary < Assembly , string > ( ) ) ;
360
363
}
361
364
}
@@ -374,7 +377,7 @@ internal static void ScanAssembly(Assembly assembly)
374
377
375
378
public static AssemblyName [ ] ListAssemblies ( )
376
379
{
377
- List < AssemblyName > names = new List < AssemblyName > ( assemblies . Count ) ;
380
+ var names = new List < AssemblyName > ( assemblies . Count ) ;
378
381
foreach ( Assembly assembly in assemblies )
379
382
{
380
383
names . Add ( assembly . GetName ( ) ) ;
@@ -388,18 +391,15 @@ public static AssemblyName[] ListAssemblies()
388
391
/// </summary>
389
392
public static bool IsValidNamespace ( string name )
390
393
{
391
- return ! String . IsNullOrEmpty ( name ) && namespaces . ContainsKey ( name ) ;
394
+ return ! string . IsNullOrEmpty ( name ) && namespaces . ContainsKey ( name ) ;
392
395
}
393
396
394
397
/// <summary>
395
398
/// Returns list of assemblies that declare types in a given namespace
396
399
/// </summary>
397
400
public static IEnumerable < Assembly > GetAssemblies ( string nsname )
398
401
{
399
- if ( ! namespaces . ContainsKey ( nsname ) )
400
- return new List < Assembly > ( ) ;
401
-
402
- return namespaces [ nsname ] . Keys ;
402
+ return ! namespaces . ContainsKey ( nsname ) ? new List < Assembly > ( ) : namespaces [ nsname ] . Keys ;
403
403
}
404
404
405
405
/// <summary>
@@ -408,7 +408,7 @@ public static IEnumerable<Assembly> GetAssemblies(string nsname)
408
408
public static List < string > GetNames ( string nsname )
409
409
{
410
410
//Dictionary<string, int> seen = new Dictionary<string, int>();
411
- List < string > names = new List < string > ( 8 ) ;
411
+ var names = new List < string > ( 8 ) ;
412
412
413
413
List < string > g = GenericUtil . GetGenericBaseNames ( nsname ) ;
414
414
if ( g != null )
@@ -424,9 +424,8 @@ public static List<string> GetNames(string nsname)
424
424
foreach ( Assembly a in namespaces [ nsname ] . Keys )
425
425
{
426
426
Type [ ] types = a . GetTypes ( ) ;
427
- for ( int i = 0 ; i < types . Length ; i ++ )
427
+ foreach ( Type t in types )
428
428
{
429
- Type t = types [ i ] ;
430
429
if ( ( t . Namespace ?? "" ) == nsname )
431
430
{
432
431
names . Add ( t . Name ) ;
0 commit comments