@@ -21,8 +21,10 @@ internal class AssemblyManager
2121 //static Dictionary<string, Dictionary<string, string>> generics;
2222 static AssemblyLoadEventHandler lhandler ;
2323 static ResolveEventHandler rhandler ;
24+
2425 // updated only under GIL?
2526 static Dictionary < string , int > probed ;
27+
2628 // modified from event handlers below, potentially triggered from different .NET threads
2729 static AssemblyList assemblies ;
2830 internal static List < string > pypath ;
@@ -53,7 +55,7 @@ internal static void Initialize()
5355 domain . AssemblyResolve += rhandler ;
5456
5557 Assembly [ ] items = domain . GetAssemblies ( ) ;
56- foreach ( var a in items )
58+ foreach ( Assembly a in items )
5759 {
5860 try
5961 {
@@ -62,7 +64,7 @@ internal static void Initialize()
6264 }
6365 catch ( Exception ex )
6466 {
65- Debug . WriteLine ( string . Format ( "Error scanning assembly {0}. {1}" , a , ex ) ) ;
67+ Debug . WriteLine ( "Error scanning assembly {0}. {1}" , a , ex ) ;
6668 }
6769 }
6870 }
@@ -86,7 +88,7 @@ internal static void Shutdown()
8688 /// so that we can know about assemblies that get loaded after the
8789 /// Python runtime is initialized.
8890 /// </summary>
89- static void AssemblyLoadHandler ( Object ob , AssemblyLoadEventArgs args )
91+ private static void AssemblyLoadHandler ( object ob , AssemblyLoadEventArgs args )
9092 {
9193 Assembly assembly = args . LoadedAssembly ;
9294 assemblies . Add ( assembly ) ;
@@ -101,7 +103,7 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args)
101103 /// for failed loads, because they might be dependencies of something
102104 /// we loaded from Python which also needs to be found on PYTHONPATH.
103105 /// </summary>
104- static Assembly ResolveHandler ( Object ob , ResolveEventArgs args )
106+ private static Assembly ResolveHandler ( object ob , ResolveEventArgs args )
105107 {
106108 string name = args . Name . ToLower ( ) ;
107109 foreach ( Assembly a in assemblies )
@@ -135,7 +137,7 @@ internal static void UpdatePath()
135137 {
136138 pypath . Clear ( ) ;
137139 probed . Clear ( ) ;
138- for ( int i = 0 ; i < count ; i ++ )
140+ for ( var i = 0 ; i < count ; i ++ )
139141 {
140142 IntPtr item = Runtime . PyList_GetItem ( list , i ) ;
141143 string path = Runtime . GetManagedString ( item ) ;
@@ -159,7 +161,7 @@ public static string FindAssembly(string name)
159161 string path ;
160162 string temp ;
161163
162- for ( int i = 0 ; i < pypath . Count ; i ++ )
164+ for ( var i = 0 ; i < pypath . Count ; i ++ )
163165 {
164166 string head = pypath [ i ] ;
165167 if ( head == null || head . Length == 0 )
@@ -197,7 +199,7 @@ public static Assembly LoadAssembly(string name)
197199 {
198200 assembly = Assembly . Load ( name ) ;
199201 }
200- catch ( System . Exception )
202+ catch ( Exception )
201203 {
202204 //if (!(e is System.IO.FileNotFoundException))
203205 //{
@@ -221,7 +223,7 @@ public static Assembly LoadAssemblyPath(string name)
221223 {
222224 assembly = Assembly . LoadFrom ( path ) ;
223225 }
224- catch
226+ catch ( Exception )
225227 {
226228 }
227229 }
@@ -241,7 +243,9 @@ public static Assembly LoadAssemblyFullPath(string name)
241243 if ( Path . IsPathRooted ( name ) )
242244 {
243245 if ( ! Path . HasExtension ( name ) )
246+ {
244247 name = name + ".dll" ;
248+ }
245249 if ( File . Exists ( name ) )
246250 {
247251 try
@@ -287,13 +291,13 @@ public static Assembly FindLoadedAssembly(string name)
287291 public static bool LoadImplicit ( string name , bool warn = true )
288292 {
289293 string [ ] names = name . Split ( '.' ) ;
290- bool loaded = false ;
291- string s = "" ;
294+ var loaded = false ;
295+ var s = "" ;
292296 Assembly lastAssembly = null ;
293297 HashSet < Assembly > assembliesSet = null ;
294- for ( int i = 0 ; i < names . Length ; i ++ )
298+ for ( var i = 0 ; i < names . Length ; i ++ )
295299 {
296- s = ( i == 0 ) ? names [ 0 ] : s + "." + names [ i ] ;
300+ s = i == 0 ? names [ 0 ] : s + "." + names [ i ] ;
297301 if ( ! probed . ContainsKey ( s ) )
298302 {
299303 if ( assembliesSet == null )
@@ -321,7 +325,7 @@ public static bool LoadImplicit(string name, bool warn = true)
321325 // Deprecation warning
322326 if ( warn && loaded )
323327 {
324- string deprWarning = String . Format (
328+ string deprWarning = string . Format (
325329 "\n The module was found, but not in a referenced namespace.\n " +
326330 "Implicit loading is deprecated. Please use clr.AddReference(\" {0}\" )." ,
327331 Path . GetFileNameWithoutExtension ( lastAssembly . Location ) ) ;
@@ -345,24 +349,23 @@ internal static void ScanAssembly(Assembly assembly)
345349 // the assembly.
346350
347351 Type [ ] types = assembly . GetTypes ( ) ;
348- for ( int i = 0 ; i < types . Length ; i ++ )
352+ foreach ( Type t in types )
349353 {
350- Type t = types [ i ] ;
351354 string ns = t . Namespace ?? "" ;
352355 if ( ! namespaces . ContainsKey ( ns ) )
353356 {
354357 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 ++ )
357360 {
358- s = ( n == 0 ) ? names [ 0 ] : s + "." + names [ n ] ;
361+ s = n == 0 ? names [ 0 ] : s + "." + names [ n ] ;
359362 namespaces . TryAdd ( s , new ConcurrentDictionary < Assembly , string > ( ) ) ;
360363 }
361364 }
362365
363366 if ( ns != null )
364367 {
365- namespaces [ ns ] . TryAdd ( assembly , String . Empty ) ;
368+ namespaces [ ns ] . TryAdd ( assembly , string . Empty ) ;
366369 }
367370
368371 if ( ns != null && t . IsGenericTypeDefinition )
@@ -374,7 +377,7 @@ internal static void ScanAssembly(Assembly assembly)
374377
375378 public static AssemblyName [ ] ListAssemblies ( )
376379 {
377- List < AssemblyName > names = new List < AssemblyName > ( assemblies . Count ) ;
380+ var names = new List < AssemblyName > ( assemblies . Count ) ;
378381 foreach ( Assembly assembly in assemblies )
379382 {
380383 names . Add ( assembly . GetName ( ) ) ;
@@ -388,18 +391,15 @@ public static AssemblyName[] ListAssemblies()
388391 /// </summary>
389392 public static bool IsValidNamespace ( string name )
390393 {
391- return ! String . IsNullOrEmpty ( name ) && namespaces . ContainsKey ( name ) ;
394+ return ! string . IsNullOrEmpty ( name ) && namespaces . ContainsKey ( name ) ;
392395 }
393396
394397 /// <summary>
395398 /// Returns list of assemblies that declare types in a given namespace
396399 /// </summary>
397400 public static IEnumerable < Assembly > GetAssemblies ( string nsname )
398401 {
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 ;
403403 }
404404
405405 /// <summary>
@@ -408,7 +408,7 @@ public static IEnumerable<Assembly> GetAssemblies(string nsname)
408408 public static List < string > GetNames ( string nsname )
409409 {
410410 //Dictionary<string, int> seen = new Dictionary<string, int>();
411- List < string > names = new List < string > ( 8 ) ;
411+ var names = new List < string > ( 8 ) ;
412412
413413 List < string > g = GenericUtil . GetGenericBaseNames ( nsname ) ;
414414 if ( g != null )
@@ -424,9 +424,8 @@ public static List<string> GetNames(string nsname)
424424 foreach ( Assembly a in namespaces [ nsname ] . Keys )
425425 {
426426 Type [ ] types = a . GetTypes ( ) ;
427- for ( int i = 0 ; i < types . Length ; i ++ )
427+ foreach ( Type t in types )
428428 {
429- Type t = types [ i ] ;
430429 if ( ( t . Namespace ?? "" ) == nsname )
431430 {
432431 names . Add ( t . Name ) ;
0 commit comments