@@ -21,8 +21,10 @@ internal class AssemblyManager
2121//static Dictionary<string, Dictionary<string, string>> generics;
2222static AssemblyLoadEventHandler lhandler ;
2323static ResolveEventHandler rhandler ;
24+
2425// updated only under GIL?
2526static Dictionary < string , int > probed ;
27+
2628// modified from event handlers below, potentially triggered from different .NET threads
2729static AssemblyList assemblies ;
2830internal static List < string > pypath ;
@@ -53,7 +55,7 @@ internal static void Initialize()
5355domain . AssemblyResolve += rhandler ;
5456
5557Assembly [ ] items = domain . GetAssemblies ( ) ;
56- foreach ( var a in items )
58+ foreach ( Assembly a in items )
5759{
5860try
5961{
@@ -62,7 +64,7 @@ internal static void Initialize()
6264}
6365catch ( 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{
9193Assembly assembly = args . LoadedAssembly ;
9294assemblies . 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{
106108string name = args . Name . ToLower ( ) ;
107109foreach ( Assembly a in assemblies )
@@ -197,7 +199,7 @@ public static Assembly LoadAssembly(string name)
197199{
198200assembly = 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{
222224assembly = Assembly . LoadFrom ( path ) ;
223225}
224- catch
226+ catch ( Exception )
225227{
226228}
227229}
@@ -241,7 +243,9 @@ public static Assembly LoadAssemblyFullPath(string name)
241243if ( Path . IsPathRooted ( name ) )
242244{
243245if ( ! Path . HasExtension ( name ) )
246+ {
244247name = name + ".dll" ;
248+ }
245249if ( File . Exists ( name ) )
246250{
247251try
@@ -287,13 +291,13 @@ public static Assembly FindLoadedAssembly(string name)
287291public static bool LoadImplicit ( string name , bool warn = true )
288292{
289293string [ ] names = name . Split ( '.' ) ;
290- bool loaded = false ;
291- string s = "" ;
294+ var loaded = false ;
295+ var s = "" ;
292296Assembly lastAssembly = null ;
293297HashSet < 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 ] ;
297301if ( ! probed . ContainsKey ( s ) )
298302{
299303if ( assembliesSet == null )
@@ -321,7 +325,7 @@ public static bool LoadImplicit(string name, bool warn = true)
321325// Deprecation warning
322326if ( 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}\" )." ,
327331Path . GetFileNameWithoutExtension ( lastAssembly . Location ) ) ;
@@ -345,17 +349,16 @@ internal static void ScanAssembly(Assembly assembly)
345349// the assembly.
346350
347351Type [ ] types = assembly . GetTypes ( ) ;
348- for ( int i = 0 ; i < types . Length ; i ++ )
352+ foreach ( Type t in types )
349353{
350- Type t = types [ i ] ;
351354string ns = t . Namespace ?? "" ;
352355if ( ! namespaces . ContainsKey ( ns ) )
353356{
354357string [ ] 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 ] ;
359362namespaces . TryAdd ( s , new ConcurrentDictionary < Assembly , string > ( ) ) ;
360363}
361364}
@@ -374,7 +377,7 @@ internal static void ScanAssembly(Assembly assembly)
374377
375378public static AssemblyName [ ] ListAssemblies ( )
376379{
377- List < AssemblyName > names = new List < AssemblyName > ( assemblies . Count ) ;
380+ var names = new List < AssemblyName > ( assemblies . Count ) ;
378381foreach ( Assembly assembly in assemblies )
379382{
380383names . Add ( assembly . GetName ( ) ) ;
@@ -388,18 +391,15 @@ public static AssemblyName[] ListAssemblies()
388391/// </summary>
389392public 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>
397400public 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)
408408public 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
413413List < string > g = GenericUtil . GetGenericBaseNames ( nsname ) ;
414414if ( g != null )
@@ -424,9 +424,8 @@ public static List<string> GetNames(string nsname)
424424foreach ( Assembly a in namespaces [ nsname ] . Keys )
425425{
426426Type [ ] types = a . GetTypes ( ) ;
427- for ( int i = 0 ; i < types . Length ; i ++ )
427+ foreach ( Type t in types )
428428{
429- Type t = types [ i ] ;
430429if ( ( t . Namespace ?? "" ) == nsname )
431430{
432431names . Add ( t . Name ) ;