diff --git a/ICSharpCode.NRefactory.CSharp/Ast/AstNodeCollection.cs b/ICSharpCode.NRefactory.CSharp/Ast/AstNodeCollection.cs
index 4e28849be4..b727dc2112 100644
--- a/ICSharpCode.NRefactory.CSharp/Ast/AstNodeCollection.cs
+++ b/ICSharpCode.NRefactory.CSharp/Ast/AstNodeCollection.cs
@@ -204,5 +204,21 @@ namespace ICSharpCode.NRefactory.CSharp
{
node.InsertChildBefore(existingItem, newItem, role);
}
+
+ ///
+ /// Applies the to all nodes in this collection.
+ ///
+ public void AcceptVisitor(IAstVisitor visitor)
+ {
+ AstNode next;
+ for (AstNode cur = node.FirstChild; cur != null; cur = next) {
+ Debug.Assert(cur.Parent == node);
+ // Remember next before yielding cur.
+ // This allows removing/replacing nodes while iterating through the list.
+ next = cur.NextSibling;
+ if (cur.Role == role)
+ cur.AcceptVisitor(visitor);
+ }
+ }
}
}
diff --git a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
index e4322822f9..0eb735a759 100644
--- a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
+++ b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
@@ -55,6 +55,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// the Cecil objects to stay in memory (which can significantly increase memory usage).
/// It also prevents serialization of the Cecil-loaded type system.
///
+ ///
+ /// Because the type system can be used on multiple threads, but Cecil is not
+ /// thread-safe for concurrent read access, the CecilLoader will lock on the instance
+ /// for every delay-loading operation.
+ /// If you access the Cecil objects directly in your application, you may need to take the same lock.
+ ///
public bool LazyLoad { get; set; }
///
@@ -72,6 +78,17 @@ namespace ICSharpCode.NRefactory.TypeSystem
///
public CancellationToken CancellationToken { get; set; }
+ ///
+ /// This delegate gets executed whenever an entity was loaded.
+ ///
+ ///
+ /// This callback may be to build a dictionary that maps between
+ /// entities and cecil objects.
+ /// Warning: if delay-loading is used and the type system is accessed by multiple threads,
+ /// the callback may be invoked concurrently on multiple threads.
+ ///
+ public Action OnEntityLoaded { get; set; }
+
///
/// Gets a value indicating whether this instance stores references to the cecil objects.
///
@@ -84,19 +101,26 @@ namespace ICSharpCode.NRefactory.TypeSystem
ModuleDefinition currentModule;
CecilUnresolvedAssembly currentAssembly;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public CecilLoader()
+ {
+ // Enable interning by default.
+ this.InterningProvider = new SimpleInterningProvider();
+ }
+
///
/// Initializes a new instance of the class.
///
///
/// If true references to the cecil objects are hold. In this case the cecil loader can do a type system -> cecil mapping.
///
- public CecilLoader (bool createCecilReferences = false)
+ [Obsolete("The built-in entity<->cecil mapping is obsolete. Use the OnEntityLoaded callback instead!")]
+ public CecilLoader(bool createCecilReferences) : this()
{
if (createCecilReferences)
typeSystemTranslationTable = new Dictionary