protected Type SearchAssemblyList(string targetType) { if (String.IsNullOrEmpty(targetType)) { return(null); } int i = targetType.LastIndexOf('.'); if (i == -1) { return(null); } string ns = targetType.Substring(0, i); /* * Get all the assemblies containing the target * type's namespace. */ List <string> assemblySearchList = new List <string>(); assemblySearchList.AddRange( referenceManager.GetNamespaceAssemblies(ns)); /* * Add all the workspace assemblies (we just search them * all as there shouldn't be too many). The list will * be empty if we've not called UpdateLists(). */ assemblySearchList.AddRange(workspaceAssemblyList); foreach (string name in assemblySearchList) { try { Assembly assembly = CodeAssistTools.LoadAssembly(name); if (assembly == null) { continue; } Type type = assembly.GetType(targetType, false); if (type != null && !type.IsNotPublic) { return(type); } } catch { // Ignore unloadable assemblies } } return(null); }
private void ColourizeVariablesAndTypes( QuickSharp.Editor.ScintillaEditForm document) { string source = document.GetContent() as string; source = CSharpFormattingTools.RemoveUnwantedText(source); source = CSharpFormattingTools.RemoveUnwantedBracketText(source); List <string> namespaces = GetNamespaceList(source); if (settingsManager.ColorizeTypes) { // Lexer WORD2 - types List <string> assemblies = new List <string>(); foreach (string ns in namespaces) { List <string> names = referenceManager.GetNamespaceAssemblies(ns); foreach (string name in names) { if (!assemblies.Contains(name)) { assemblies.Add(name); } } } assemblies.AddRange(workspaceAssemblyList); document.Editor.Lexing.Keywords[1] = "Array Boolean Date Enumerator Error Function Number Object RegExp String VBArray " + CodeAssistTools.GetNamespaceTypesAsString( namespaces, assemblies); } if (settingsManager.ColorizeVariables) { // Lexer GLOBALCLASS - variables DeclaredVariables declaredVariables = new DeclaredVariables(source, fullNamespaceList, false); StringBuilder sb = new StringBuilder(); foreach (Variable v in declaredVariables.Items) { sb.Append(v.Name); sb.Append(" "); } document.Editor.Lexing.Keywords[3] = sb.ToString(); } document.Editor.Lexing.Colorize(); }
private void ColourizeVariablesAndTypes(ScintillaEditForm document) { string source = CSharpFormattingTools. RemoveUnwantedText(document.GetContent() as string); source = CSharpFormattingTools. RemoveUnwantedBracketText(source); List <string> namespaces = GetNamespaceList(source); if (settingsManager.ColorizeTypes) { /* * Lexer WORD2 - types */ List <string> assemblies = new List <string>(); foreach (string ns in namespaces) { List <string> names = referenceManager.GetNamespaceAssemblies(ns); foreach (string name in names) { if (!assemblies.Contains(name)) { assemblies.Add(name); } } } assemblies.AddRange(workspaceAssemblyList); document.Editor.Lexing.Keywords[1] = CodeAssistTools.GetNamespaceTypesAsString( namespaces, assemblies); } if (settingsManager.ColorizeVariables) { /* * Lexer GLOBALCLASS - variables */ DeclaredVariables declaredVariables = new DeclaredVariables( source, namespaces, false, DeclarationContext.All); InheritedVariablesBase inheritedVariables = new InheritedVariablesCode( source, DeclarationContext.All, workspaceAssemblyList, fullNamespaceList, rootNamespaceList, configNamespaceList); StringBuilder sb = new StringBuilder(); foreach (Variable v in declaredVariables.Items) { sb.Append(v.Name); sb.Append(" "); } foreach (Variable v in inheritedVariables.Items) { sb.Append(v.Name); sb.Append(" "); } document.Editor.Lexing.Keywords[3] = sb.ToString(); } document.Editor.Lexing.Colorize(); }
protected void UpdateLists() { /* * Update the workspace cache and get the * assemblies as a list. */ workspaceAssemblyList.Clear(); workspaceAssemblyList.AddRange( cacheManager.UpdateAssemblyCache()); /* * Build the namespace lists. */ fullNamespaceList.Clear(); fullNamespaceList.AddRange(referenceManager.FullNamespaceList); rootNamespaceList.Clear(); rootNamespaceList.AddRange(referenceManager.RootNamespaceList); foreach (string name in workspaceAssemblyList) { Assembly assembly = CodeAssistTools.LoadAssembly(name); if (assembly == null) { continue; } try { foreach (Type type in assembly.GetTypes()) { string ns = type.Namespace; if (String.IsNullOrEmpty(ns)) { continue; } if (!fullNamespaceList.Contains(ns)) { fullNamespaceList.Add(ns); } string[] split = ns.Split('.'); if (String.IsNullOrEmpty(split[0])) { continue; } if (!rootNamespaceList.Contains(split[0])) { rootNamespaceList.Add(split[0]); } } } catch { // Ignore unloadable assemblies } } }
/* * Find the types belonging to a list of namespaces. */ protected List <Type> FindNamespaceTypes( List <string> parentNamespaceList) { List <Type> types = new List <Type>(); List <string> assemblySearchList = new List <string>(); /* * Get the assemblies containing the namespaces. */ foreach (string ns in parentNamespaceList) { List <string> assemblyList = new List <string>(); assemblyList.AddRange( referenceManager.GetNamespaceAssemblies(ns)); foreach (string assemblyRef in assemblyList) { if (!assemblySearchList.Contains(assemblyRef)) { assemblySearchList.Add(assemblyRef); } } } assemblySearchList.AddRange(workspaceAssemblyList); /* * Get the types. */ foreach (string assemblyRef in assemblySearchList) { Assembly assembly = CodeAssistTools.LoadAssembly(assemblyRef); if (assembly == null) { continue; } try { foreach (Type type in assembly.GetTypes()) { if (type.IsNotPublic) { continue; } if (!type.IsVisible) { continue; } if (type.Namespace == null) { continue; } if (parentNamespaceList.Contains(type.Namespace)) { types.Add(type); } } } catch { // Just skip any problematic assemblies } } return(types); }
private void GetNamespaceTypes(TreeNode node) { node.Nodes.Clear(); // Keep track of found types so we don't add dupes. List <string> typeNames = new List <string>(); /* * Go through each assembly containing the namespace * and get the types contained within it. */ List <string> assemblyNames = new List <string>(); /* * If using namespace view add all assemblies containing the * namespace, otherwise just include the selected assembly. */ if (_showModules) { if (node.Parent != null) { /* * Add the selected assembly. */ ModuleData moduleData = node.Parent.Tag as ModuleData; if (moduleData != null) { Assembly assembly = moduleData.Module.Assembly; if (!moduleData.IsWorkspaceAssembly) { assemblyNames.Add(assembly.FullName); } else { assemblyNames.Add("?" + moduleData.FullName); } } } } else { /* * Add the assemblies that are known to cantain the namespace * and all the local ones (no way of telling if they do). */ assemblyNames.AddRange( _referenceManager.GetNamespaceAssemblies(node.Text)); if (_includeWorkspace) { assemblyNames.AddRange(_workspaceAssemblies); } } foreach (string name in assemblyNames) { Assembly assembly = CodeAssistTools.LoadAssembly(name); if (assembly == null) { continue; } try { foreach (Type type in assembly.GetTypes()) { if (typeNames.Contains(type.FullName)) { continue; } if (type.IsNested) { continue; } if (_hideNonPublicMembers && type.IsNotPublic) { continue; } // Reject types not in the namespace we're looking for. if (String.IsNullOrEmpty(type.Namespace)) { continue; } if (type.Namespace != node.Text) { continue; } string typeName = CSharpFormattingTools.GetTypeSignature(type); TreeNode typeNode = CreateTreeNode(type, typeName); node.Nodes.Add(typeNode); typeNames.Add(type.FullName); AddNestedTypes(type, typeName, node); } } catch { // Just suppress any errors from problematic assemblies. } } }
private void LoadModuleMembers(string assemblyName) { Assembly assembly = CodeAssistTools.LoadAssembly(assemblyName); if (assembly == null) { return; } foreach (System.Reflection.Module module in assembly.GetModules()) { string moduleName = module.Name; // Remove '.dll' if (moduleName.Length > 4) { moduleName = moduleName.Substring( 0, moduleName.Length - 4); } bool isWorkspaceAssembly = false; if (assemblyName[0] == '@') { isWorkspaceAssembly = true; } else if (assemblyName[0] == '?' && moduleName.Length > 37) { // 'LoadFile' context, remove local cache signature. moduleName = moduleName.Substring(37); isWorkspaceAssembly = true; } ModuleData moduleData = new ModuleData(); moduleData.Name = moduleName; moduleData.FullName = module.FullyQualifiedName; moduleData.IsWorkspaceAssembly = isWorkspaceAssembly; moduleData.Module = module; /* * Gather all the namespaces in the module. As * always we have to do this the hard way by * looking at each type and adding each new * namespace to the list. */ try { foreach (Type type in module.GetTypes()) { if (type.IsNested) { continue; } if (_hideNonPublicMembers && type.IsNotPublic) { continue; } string namespaceName = type.Namespace; if (String.IsNullOrEmpty(namespaceName)) { continue; } if (!isWorkspaceAssembly && !_referenceManager.FullNamespaceList. Contains(namespaceName)) { continue; } if (!moduleData.NamespaceNodes. ContainsKey(namespaceName)) { moduleData.NamespaceNodes[namespaceName] = new List <TreeNode>(); } } } catch { // Just skip problematic modules. } _modules[moduleName] = moduleData; } }