Пример #1
0
		/// <summary>
		/// Search for type name.
		/// </summary>
		/// <param name="list">Array of items where to search.</param>
		/// <param name="filter">Filter to search.</param>
		/// <returns><c>true</c>, if call succeded, <c>false</c> otherwise.</returns>
		bool SearchTypesName(ListViewItem[] list, string filter)
		{
			// return null if list is null
			if (list == null) return false;
			
			// return if filter is empty
			if (string.IsNullOrEmpty(filter)) {
				resultList = list.ToList();
				return true;
			}
			
			// clear result
			resultList.Clear();
			
			// scan the list
			for (int i = 0; i < list.Length; ++i) {
				ListViewItem item = list[i];
				DomAssemblyName asm = item.Tag as DomAssemblyName;

				// search path
				if (asm.FullName.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)
					resultList.Add(item);
				else {
					if (worker.CancellationPending)
					    return false;
					
					// search using Mono.Cecil the class/interface/structs names 
					AssemblyDefinition currentAssembly;
					if(!assembliesCache.ContainsKey(asm.FullName)) {	
						try {
							currentAssembly = resolver.Resolve(asm.FullName);
						}
						catch {
							continue;
						}
						assembliesCache.Add(asm.FullName, currentAssembly);							
					}
					else
						currentAssembly = assembliesCache[asm.FullName];
					
					// search types in modules
					if (currentAssembly != null) {
						foreach(var module in currentAssembly.Modules)
							foreach (var type in module.Types) 
								if (type.Name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0 && 
								    !resultList.Contains(item))
									resultList.Add(item);									
					}
					
					// report
					worker.ReportProgress((int)(((i * 1.0) / list.Length) * 100));
				}
			}
						
			return true;
		}