@@ -31,12 +31,11 @@ private AssemblyManager()
31
31
{
32
32
}
33
33
34
- //===================================================================
35
- // Initialization performed on startup of the Python runtime. Here we
36
- // scan all of the currently loaded assemblies to determine exported
37
- // names, and register to be notified of new assembly loads.
38
- //===================================================================
39
-
34
+ /// <summary>
35
+ /// Initialization performed on startup of the Python runtime. Here we
36
+ /// scan all of the currently loaded assemblies to determine exported
37
+ /// names, and register to be notified of new assembly loads.
38
+ /// </summary>
40
39
internal static void Initialize ( )
41
40
{
42
41
namespaces = new ConcurrentDictionary < string , ConcurrentDictionary < Assembly , string > > ( ) ;
@@ -69,10 +68,9 @@ internal static void Initialize()
69
68
}
70
69
71
70
72
- //===================================================================
73
- // Cleanup resources upon shutdown of the Python runtime.
74
- //===================================================================
75
-
71
+ /// <summary>
72
+ /// Cleanup resources upon shutdown of the Python runtime.
73
+ /// </summary>
76
74
internal static void Shutdown ( )
77
75
{
78
76
AppDomain domain = AppDomain . CurrentDomain ;
@@ -81,14 +79,13 @@ internal static void Shutdown()
81
79
}
82
80
83
81
84
- //===================================================================
85
- // Event handler for assembly load events. At the time the Python
86
- // runtime loads, we scan the app domain to map the assemblies that
87
- // are loaded at the time. We also have to register this event handler
88
- // so that we can know about assemblies that get loaded after the
89
- // Python runtime is initialized.
90
- //===================================================================
91
-
82
+ /// <summary>
83
+ /// Event handler for assembly load events. At the time the Python
84
+ /// runtime loads, we scan the app domain to map the assemblies that
85
+ /// are loaded at the time. We also have to register this event handler
86
+ /// so that we can know about assemblies that get loaded after the
87
+ /// Python runtime is initialized.
88
+ /// </summary>
92
89
static void AssemblyLoadHandler ( Object ob , AssemblyLoadEventArgs args )
93
90
{
94
91
Assembly assembly = args . LoadedAssembly ;
@@ -97,14 +94,13 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args)
97
94
}
98
95
99
96
100
- //===================================================================
101
- // Event handler for assembly resolve events. This is needed because
102
- // we augment the assembly search path with the PYTHONPATH when we
103
- // load an assembly from Python. Because of that, we need to listen
104
- // for failed loads, because they might be dependencies of something
105
- // we loaded from Python which also needs to be found on PYTHONPATH.
106
- //===================================================================
107
-
97
+ /// <summary>
98
+ /// Event handler for assembly resolve events. This is needed because
99
+ /// we augment the assembly search path with the PYTHONPATH when we
100
+ /// load an assembly from Python. Because of that, we need to listen
101
+ /// for failed loads, because they might be dependencies of something
102
+ /// we loaded from Python which also needs to be found on PYTHONPATH.
103
+ /// </summary>
108
104
static Assembly ResolveHandler ( Object ob , ResolveEventArgs args )
109
105
{
110
106
string name = args . Name . ToLower ( ) ;
@@ -120,19 +116,17 @@ static Assembly ResolveHandler(Object ob, ResolveEventArgs args)
120
116
}
121
117
122
118
123
- //===================================================================
124
- // We __really__ want to avoid using Python objects or APIs when
125
- // probing for assemblies to load, since our ResolveHandler may be
126
- // called in contexts where we don't have the Python GIL and can't
127
- // even safely try to get it without risking a deadlock ;(
128
- //
129
- // To work around that, we update a managed copy of sys.path (which
130
- // is the main thing we care about) when UpdatePath is called. The
131
- // import hook calls this whenever it knows its about to use the
132
- // assembly manager, which lets us keep up with changes to sys.path
133
- // in a relatively lightweight and low-overhead way.
134
- //===================================================================
135
-
119
+ /// <summary>
120
+ /// We __really__ want to avoid using Python objects or APIs when
121
+ /// probing for assemblies to load, since our ResolveHandler may be
122
+ /// called in contexts where we don't have the Python GIL and can't
123
+ /// even safely try to get it without risking a deadlock ;(
124
+ /// To work around that, we update a managed copy of sys.path (which
125
+ /// is the main thing we care about) when UpdatePath is called. The
126
+ /// import hook calls this whenever it knows its about to use the
127
+ /// assembly manager, which lets us keep up with changes to sys.path
128
+ /// in a relatively lightweight and low-overhead way.
129
+ /// </summary>
136
130
internal static void UpdatePath ( )
137
131
{
138
132
IntPtr list = Runtime . PySys_GetObject ( "path" ) ;
@@ -154,12 +148,11 @@ internal static void UpdatePath()
154
148
}
155
149
156
150
157
- //===================================================================
158
- // Given an assembly name, try to find this assembly file using the
159
- // PYTHONPATH. If not found, return null to indicate implicit load
160
- // using standard load semantics (app base directory then GAC, etc.)
161
- //===================================================================
162
-
151
+ /// <summary>
152
+ /// Given an assembly name, try to find this assembly file using the
153
+ /// PYTHONPATH. If not found, return null to indicate implicit load
154
+ /// using standard load semantics (app base directory then GAC, etc.)
155
+ /// </summary>
163
156
public static string FindAssembly ( string name )
164
157
{
165
158
char sep = Path . DirectorySeparatorChar ;
@@ -193,11 +186,10 @@ public static string FindAssembly(string name)
193
186
}
194
187
195
188
196
- //===================================================================
197
- // Loads an assembly from the application directory or the GAC
198
- // given a simple assembly name. Returns the assembly if loaded.
199
- //===================================================================
200
-
189
+ /// <summary>
190
+ /// Loads an assembly from the application directory or the GAC
191
+ /// given a simple assembly name. Returns the assembly if loaded.
192
+ /// </summary>
201
193
public static Assembly LoadAssembly ( string name )
202
194
{
203
195
Assembly assembly = null ;
@@ -216,10 +208,9 @@ public static Assembly LoadAssembly(string name)
216
208
}
217
209
218
210
219
- //===================================================================
220
- // Loads an assembly using an augmented search path (the python path).
221
- //===================================================================
222
-
211
+ /// <summary>
212
+ /// Loads an assembly using an augmented search path (the python path).
213
+ /// </summary>
223
214
public static Assembly LoadAssemblyPath ( string name )
224
215
{
225
216
string path = FindAssembly ( name ) ;
@@ -240,8 +231,10 @@ public static Assembly LoadAssemblyPath(string name)
240
231
/// <summary>
241
232
/// Loads an assembly using full path.
242
233
/// </summary>
243
- /// <param name="name"></param>
244
- /// <returns></returns>
234
+ /// <param name="name">
235
+ /// </param>
236
+ /// <returns>
237
+ /// </returns>
245
238
public static Assembly LoadAssemblyFullPath ( string name )
246
239
{
247
240
Assembly assembly = null ;
@@ -263,10 +256,9 @@ public static Assembly LoadAssemblyFullPath(string name)
263
256
return assembly ;
264
257
}
265
258
266
- //===================================================================
267
- // Returns an assembly that's already been loaded
268
- //===================================================================
269
-
259
+ /// <summary>
260
+ /// Returns an assembly that's already been loaded
261
+ /// </summary>
270
262
public static Assembly FindLoadedAssembly ( string name )
271
263
{
272
264
foreach ( Assembly a in assemblies )
@@ -279,18 +271,19 @@ public static Assembly FindLoadedAssembly(string name)
279
271
return null ;
280
272
}
281
273
282
- //===================================================================
283
- // Given a qualified name of the form A.B.C.D, attempt to load
284
- // an assembly named after each of A.B.C.D, A.B.C, A.B, A. This
285
- // will only actually probe for the assembly once for each unique
286
- // namespace. Returns true if any assemblies were loaded.
287
- // TODO item 3 "* Deprecate implicit loading of assemblies":
288
- // Set the fromFile flag if the name of the loaded assembly matches
289
- // the fully qualified name that was requested if the framework
290
- // actually loads an assembly.
291
- // Call ONLY for namespaces that HAVE NOT been cached yet.
292
- //===================================================================
293
-
274
+ /// <summary>
275
+ /// Given a qualified name of the form A.B.C.D, attempt to load
276
+ /// an assembly named after each of A.B.C.D, A.B.C, A.B, A. This
277
+ /// will only actually probe for the assembly once for each unique
278
+ /// namespace. Returns true if any assemblies were loaded.
279
+ /// </summary>
280
+ /// <remarks>
281
+ /// TODO item 3 "* Deprecate implicit loading of assemblies":
282
+ /// Set the fromFile flag if the name of the loaded assembly matches
283
+ /// the fully qualified name that was requested if the framework
284
+ /// actually loads an assembly.
285
+ /// Call ONLY for namespaces that HAVE NOT been cached yet.
286
+ /// </remarks>
294
287
public static bool LoadImplicit ( string name , bool warn = true )
295
288
{
296
289
string [ ] names = name . Split ( '.' ) ;
@@ -339,13 +332,12 @@ public static bool LoadImplicit(string name, bool warn = true)
339
332
}
340
333
341
334
342
- //===================================================================
343
- // Scans an assembly for exported namespaces, adding them to the
344
- // mapping of valid namespaces. Note that for a given namespace
345
- // a.b.c.d, each of a, a.b, a.b.c and a.b.c.d are considered to
346
- // be valid namespaces (to better match Python import semantics).
347
- //===================================================================
348
-
335
+ /// <summary>
336
+ /// Scans an assembly for exported namespaces, adding them to the
337
+ /// mapping of valid namespaces. Note that for a given namespace
338
+ /// a.b.c.d, each of a, a.b, a.b.c and a.b.c.d are considered to
339
+ /// be valid namespaces (to better match Python import semantics).
340
+ /// </summary>
349
341
internal static void ScanAssembly ( Assembly assembly )
350
342
{
351
343
// A couple of things we want to do here: first, we want to
@@ -390,20 +382,18 @@ public static AssemblyName[] ListAssemblies()
390
382
return names . ToArray ( ) ;
391
383
}
392
384
393
- //===================================================================
394
- // Returns true if the given qualified name matches a namespace
395
- // exported by an assembly loaded in the current app domain.
396
- //===================================================================
397
-
385
+ /// <summary>
386
+ /// Returns true if the given qualified name matches a namespace
387
+ /// exported by an assembly loaded in the current app domain.
388
+ /// </summary>
398
389
public static bool IsValidNamespace ( string name )
399
390
{
400
391
return ! String . IsNullOrEmpty ( name ) && namespaces . ContainsKey ( name ) ;
401
392
}
402
393
403
- //===================================================================
404
- // Returns list of assemblies that declare types in a given namespace
405
- //===================================================================
406
-
394
+ /// <summary>
395
+ /// Returns list of assemblies that declare types in a given namespace
396
+ /// </summary>
407
397
public static IEnumerable < Assembly > GetAssemblies ( string nsname )
408
398
{
409
399
if ( ! namespaces . ContainsKey ( nsname ) )
@@ -412,10 +402,9 @@ public static IEnumerable<Assembly> GetAssemblies(string nsname)
412
402
return namespaces [ nsname ] . Keys ;
413
403
}
414
404
415
- //===================================================================
416
- // Returns the current list of valid names for the input namespace.
417
- //===================================================================
418
-
405
+ /// <summary>
406
+ /// Returns the current list of valid names for the input namespace.
407
+ /// </summary>
419
408
public static List < string > GetNames ( string nsname )
420
409
{
421
410
//Dictionary<string, int> seen = new Dictionary<string, int>();
@@ -460,12 +449,11 @@ public static List<string> GetNames(string nsname)
460
449
return names ;
461
450
}
462
451
463
- //===================================================================
464
- // Returns the System.Type object for a given qualified name,
465
- // looking in the currently loaded assemblies for the named
466
- // type. Returns null if the named type cannot be found.
467
- //===================================================================
468
-
452
+ /// <summary>
453
+ /// Returns the System.Type object for a given qualified name,
454
+ /// looking in the currently loaded assemblies for the named
455
+ /// type. Returns null if the named type cannot be found.
456
+ /// </summary>
469
457
public static Type LookupType ( string qname )
470
458
{
471
459
foreach ( Assembly assembly in assemblies )
@@ -528,8 +516,8 @@ public IEnumerator GetEnumerator()
528
516
}
529
517
530
518
/// <summary>
531
- /// Enumerator wrapping around <see cref="AssemblyList._list"/>'s enumerator.
532
- /// Acquires and releases a read lock on <see cref="AssemblyList._lock"/> during enumeration
519
+ /// Enumerator wrapping around <see cref="AssemblyList._list" />'s enumerator.
520
+ /// Acquires and releases a read lock on <see cref="AssemblyList._lock" /> during enumeration
533
521
/// </summary>
534
522
private class Enumerator : IEnumerator < Assembly >
535
523
{
0 commit comments