diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs index 29ea7692cc..d4218544ce 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs @@ -159,6 +159,9 @@ namespace ICSharpCode.FormsDesigner { LoggingService.Debug("Forms designer: Load " + file.FileName + "; inMasterLoadOperation=" + this.inMasterLoadOperation); + if (this.typeResolutionService != null) + this.typeResolutionService.ClearCaches(); + if (inMasterLoadOperation) { if (this.sourceCodeStorage.ContainsFile(file)) { diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs index 3b484f99e6..837e3757f0 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs @@ -361,6 +361,19 @@ namespace ICSharpCode.FormsDesigner.Services return GetType(name, throwOnError, false); } + #if DEBUG + int count = 0; + #endif + + Dictionary typeCache = new Dictionary(StringComparer.Ordinal); + Dictionary typeCacheIgnoreCase = new Dictionary(StringComparer.OrdinalIgnoreCase); + + public void ClearCaches() + { + typeCacheIgnoreCase.Clear(); + typeCache.Clear(); + } + public Type GetType(string name, bool throwOnError, bool ignoreCase) { if (name == null || name.Length == 0) { @@ -369,9 +382,19 @@ namespace ICSharpCode.FormsDesigner.Services if (IgnoreType(name)) { return null; } + if (ignoreCase) { + Type cachedType; + if (typeCacheIgnoreCase.TryGetValue(name, out cachedType)) + return cachedType; + } else { + Type cachedType; + if (typeCache.TryGetValue(name, out cachedType)) + return cachedType; + } #if DEBUG if (!name.StartsWith("System.")) { - LoggingService.Debug("TypeResolutionService: Looking for " + name); + count++; + LoggingService.Debug(count + " TypeResolutionService: Looking for " + name); } #endif try { @@ -436,6 +459,7 @@ namespace ICSharpCode.FormsDesigner.Services try { Type t = asm.GetType(name, false); if (t != null) { + AddToCache(name, t, ignoreCase); return t; } } catch (FileNotFoundException) { @@ -449,7 +473,7 @@ namespace ICSharpCode.FormsDesigner.Services if (throwOnError && type == null) throw new TypeLoadException(name + " not found by TypeResolutionService"); - + AddToCache(name, type, ignoreCase); return type; } catch (Exception e) { LoggingService.Error(e); @@ -457,6 +481,17 @@ namespace ICSharpCode.FormsDesigner.Services return null; } + void AddToCache(string name, Type type, bool ignoreCase) + { + if (type == null) + return; + if (ignoreCase) { + typeCacheIgnoreCase.Add(name, type); + } else { + typeCache.Add(name, type); + } + } + public void ReferenceAssembly(AssemblyName name) { ICSharpCode.Core.LoggingService.Warn("TODO: Add Assembly reference : " + name);