123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
-
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Collections.Specialized;
- using System.IO;
- using System.Linq;
- using System.Xml.Linq;
- namespace ICSharpCode.ILSpy
- {
-
-
-
- public class AssemblyList
- {
- readonly string listName;
-
-
- bool dirty;
-
- internal readonly ConcurrentDictionary<string, LoadedAssembly> assemblyLookupCache = new ConcurrentDictionary<string, LoadedAssembly>();
- internal readonly ConcurrentDictionary<string, LoadedAssembly> winRTMetadataLookupCache = new ConcurrentDictionary<string, LoadedAssembly>();
-
-
-
-
-
-
-
-
-
-
- internal readonly List<LoadedAssembly> assemblies = new List<LoadedAssembly>();
-
- public AssemblyList(string listName)
- {
- this.listName = listName;
-
- }
-
-
-
-
- public AssemblyList(XElement listElement)
- : this((string)listElement.Attribute("name"))
- {
- foreach (var asm in listElement.Elements("Assembly")) {
- OpenAssembly((string)asm);
- }
- this.dirty = false;
- }
-
-
-
-
- public LoadedAssembly[] GetAssemblies()
- {
- lock (assemblies) {
- return assemblies.ToArray();
- }
- }
-
-
-
-
- internal XElement SaveAsXml()
- {
- return new XElement(
- "List",
- new XAttribute("name", this.ListName),
- assemblies.Where(asm => !asm.IsAutoLoaded).Select(asm => new XElement("Assembly", asm.FileName))
- );
- }
- public LoadedAssembly findAssemblyByShortName (string shortName)
- {
- foreach (LoadedAssembly asm in assemblies) {
- if (asm.ShortName == shortName) {
- return asm;
- }
- }
- return null;
- }
-
-
-
-
- public string ListName {
- get { return listName; }
- }
-
- void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
- {
- ClearCache();
-
-
- if (!dirty) {
- dirty = true;
- }
- }
- internal void RefreshSave()
- {
- if (!dirty) {
- dirty = true;
- }
- }
-
- internal void ClearCache()
- {
- assemblyLookupCache.Clear();
- winRTMetadataLookupCache.Clear();
- }
-
-
-
-
-
- public LoadedAssembly OpenAssembly(string file, bool isAutoLoaded=false)
- {
-
-
- file = Path.GetFullPath(file);
-
- foreach (LoadedAssembly asm in this.assemblies) {
- if (file.Equals(asm.FileName, StringComparison.OrdinalIgnoreCase))
- return asm;
- }
-
- var newAsm = new LoadedAssembly(this, file);
- newAsm.IsAutoLoaded = isAutoLoaded;
- lock (assemblies) {
- this.assemblies.Add(newAsm);
- }
- return newAsm;
- }
-
-
-
-
-
- public void Unload(LoadedAssembly assembly)
- {
-
- lock (assemblies) {
- assemblies.Remove(assembly);
- }
- RequestGC();
- }
-
- static bool gcRequested;
-
- void RequestGC()
- {
- if (gcRequested) return;
- gcRequested = true;
-
- }
-
- public void Sort(IComparer<LoadedAssembly> comparer)
- {
- Sort(0, int.MaxValue, comparer);
- }
-
- public void Sort(int index, int count, IComparer<LoadedAssembly> comparer)
- {
-
- lock (assemblies) {
- List<LoadedAssembly> list = new List<LoadedAssembly>(assemblies);
- list.Sort(index, Math.Min(count, list.Count - index), comparer);
- assemblies.Clear();
- assemblies.AddRange(list);
- }
- }
- }
- }
|