473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

loading multiple assemblies

1
hi friends....

I have got a problem regarding loading of multiple assemblies, actually its required for an editor which implements the intellisenseas in vb or dotnet.
for that it is required to load that assembly whose sub-classes are required to be loaded into the list box after pressing dot.

for example in the code given below i have given the path of System.dll assembly file, now all the sub class of System.Data are automatically displayed in list box but if i need to load more than one assmbly i.e 5-6 assemblies how should i do that.

source code

Expand|Select|Wrap|Line Numbers
  1. private void readAssembly()
  2. {
  3. this.treeViewItems.Nodes.Clear();
  4. namespaces = new Hashtable();
  5.  
  6. Type [] assemblyTypes = assembly.GetTypes(); 
  7. this.treeViewItems.Nodes.Clear();
  8.  
  9. // Cycle through types
  10. foreach (Type type in assemblyTypes) 
  11. {
  12. if ( type.Namespace != null )
  13. {
  14. if ( namespaces.ContainsKey(type.Namespace) )
  15. {
  16. // Already got namespace, add the class to it
  17. TreeNode treeNode = (TreeNode) namespaces[type.Namespace];
  18. treeNode = treeNode.Nodes.Add(type.Name);
  19. this.addMembers(treeNode,type);
  20.  
  21. if ( type.IsClass )
  22. {
  23. treeNode.Tag = MemberTypes.Custom;
  24. }
  25. }
  26. else
  27. {
  28. // New namespace
  29. TreeNode membersNode = null;
  30.  
  31. if ( type.Namespace.IndexOf(".") != -1 )
  32. {
  33. // Search for already existing parts of the namespace
  34. nameSpaceNode = null;
  35. foundNode = false;
  36.  
  37. this.currentPath = "";
  38. searchTree(this.treeViewItems.Nodes,type.Namespace,false);
  39.  
  40. // No existing namespace found
  41. if ( nameSpaceNode == null )
  42. {
  43. // Add the namespace
  44. string[] parts = type.Namespace.Split('.');
  45.  
  46. TreeNode treeNode = treeViewItems.Nodes.Add(parts[0]);
  47. string sNamespace = parts[0];
  48.  
  49. if ( !namespaces.ContainsKey(sNamespace) )
  50. {
  51. namespaces.Add(sNamespace,treeNode);
  52. }
  53.  
  54. for (int i=1;i < parts.Length;i++)
  55. {
  56. treeNode = treeNode.Nodes.Add(parts[i]);
  57. sNamespace += "." +parts[i];
  58. if ( !namespaces.ContainsKey(sNamespace) )
  59. {
  60. namespaces.Add(sNamespace,treeNode);
  61. }
  62. }
  63.  
  64. membersNode = treeNode.Nodes.Add(type.Name);
  65. }
  66. else
  67. {
  68. // Existing namespace, add this namespace to it,
  69. // and add the class
  70. string[] parts = type.Namespace.Split('.');
  71. TreeNode newNamespaceNode = null;
  72.  
  73. if ( !namespaces.ContainsKey(type.Namespace) )
  74. {
  75. newNamespaceNode = nameSpaceNode.Nodes.Add(parts[parts.Length-1]);
  76. namespaces.Add(type.Namespace,newNamespaceNode);
  77. }
  78. else
  79. {
  80. newNamespaceNode = (TreeNode) namespaces[type.Namespace];
  81. }
  82.  
  83. if ( newNamespaceNode != null )
  84. {
  85. membersNode = newNamespaceNode.Nodes.Add(type.Name);
  86. if ( type.IsClass )
  87. {
  88. membersNode.Tag = MemberTypes.Custom;
  89. }
  90. }
  91. }
  92.  
  93. }
  94. else
  95. {
  96. // Single root namespace, add to root
  97. membersNode = treeViewItems.Nodes.Add(type.Namespace);
  98. }
  99.  
  100. // Add all members
  101. if ( membersNode != null )
  102. {
  103. this.addMembers(membersNode,type);
  104. }
  105. }
  106. }
  107.  
  108. }
  109. }
  110.  
  111. /// 
  112. /// Adds all members to the node's children, grabbing the parameters
  113. /// for methods.
  114. /// 
  115. /// 
  116. /// 
  117. private void addMembers(TreeNode treeNode,System.Type type)
  118. {
  119. // Get all members except methods
  120. MemberInfo[] memberInfo = type.GetMembers();
  121. for (int j=0;j < memberInfo.Length;j++)
  122. if ( memberInfo[j].ReflectedType.IsPublic && memberInfo[j].MemberType != MemberTypes.Method )
  123. {
  124. TreeNode node = treeNode.Nodes.Add(memberInfo[j].Name);
  125. node.Tag = memberInfo[j].MemberType; 
  126. }
  127. }
  128.  
  129. // Get all methods
  130. MethodInfo[] methodInfo = type.GetMethods();
  131. for (int j=0;j < methodInfo.Length;j++)
  132. {
  133. TreeNode node = treeNode.Nodes.Add(methodInfo[j].Name);
  134. string parms = "";
  135.  
  136. ParameterInfo[] parameterInfo = methodInfo[j].GetParameters();
  137. for (int f=0;f < parameterInfo.Length;f++)
  138. {
  139. parms += parameterInfo[f].ParameterType.ToString()+ " " +parameterInfo[f].Name+ ", ";
  140. }
  141.  
  142. // Knock off remaining ", "
  143. if ( parms.Length > 2 )
  144. {
  145. parms = parms.Substring(0,parms.Length -2);
  146. }
  147.  
  148. node.Tag = parms;
  149. }
  150. }
  151.  
  152. /// 
  153. /// Searches the tree view for a namespace, saving the node. The method
  154. /// stops and returns as soon as the namespace search can't find any
  155. /// more items in its path, unless continueUntilFind is true.
  156. /// 
  157. /// 
  158. /// 
  159. /// 
  160. private void searchTree(TreeNodeCollection treeNodes,string path,bool continueUntilFind)
  161. {
  162. if ( this.foundNode )
  163. {
  164. return;
  165. }
  166.  
  167. string p = "";
  168. int n = 0;
  169. n = path.IndexOf(".");
  170.  
  171. if ( n != -1)
  172. {
  173. p = path.Substring(0,n);
  174.  
  175. if ( currentPath != "" )
  176. {
  177. currentPath += "." +p;
  178. }
  179. else
  180. {
  181. currentPath = p;
  182. }
  183.  
  184. // Knock off the first part
  185. path = path.Remove(0,n+1);
  186. }
  187. else
  188. {
  189. currentPath += "." +path;
  190. }
  191.  
  192. for (int i=0;i < treeNodes.Count;i++)
  193. {
  194. if ( treeNodes[i].FullPath == currentPath )
  195. {
  196. if ( continueUntilFind )
  197. {
  198. nameSpaceNode = treeNodes[i];
  199. }
  200.  
  201. nameSpaceNode = treeNodes[i];
  202.  
  203. // got a dot, continue, or return
  204. this.searchTree(treeNodes[i].Nodes,path,continueUntilFind);
  205.  
  206. }
  207. else if ( !continueUntilFind )
  208. {
  209. foundNode = true;
  210. return;
  211. }
  212. }
  213. }
  214.  
  215. /// 
  216. /// Searches the tree until the given path is found, storing
  217. /// the found node in a member var.
  218. /// 
  219. /// 
  220. /// 
  221. private void findNode(string path,TreeNodeCollection treeNodes)
  222. {
  223. for (int i=0;i < treeNodes.Count;i++)
  224. {
  225. if ( treeNodes[i].FullPath == path )
  226. {
  227. this.findNodeResult = treeNodes[i];
  228. break;
  229. }
  230. else if ( treeNodes[i].Nodes.Count > 0 )
  231. {
  232. this.findNode(path,treeNodes[i].Nodes);
  233. }
  234. }
  235. }
  236.  
  237. /// 
  238. /// Called when a "." is pressed - the previous word is found,
  239. /// and if matched in the treeview, the members listbox is
  240. /// populated with items from the tree, which are first sorted.
  241. /// 
  242. /// Whether an items are found for the word
  243. private bool populateListBox()
  244. {
  245. bool result = false;
  246. string word = this.getLastWord();
  247.  
  248. //System.Diagnostics.Debug.WriteLine(" - Path: " +word);
  249.  
  250. if ( word != "" )
  251. {
  252. findNodeResult = null;
  253. findNode(word,this.treeViewItems.Nodes); 
  254.  
  255. if (this.findNodeResult != null )
  256. {
  257. this.listBoxAutoComplete.Items.Clear();
  258.  
  259. if ( this.findNodeResult.Nodes.Count > 0 )
  260. {
  261. result = true;
  262.  
  263. // Sort alphabetically (this could be replaced with
  264. // a sortable treeview)
  265. MemberItem[] items = new MemberItem[this.findNodeResult.Nodes.Count];
  266. for (int n=0;n < this.findNodeResult.Nodes.Count;n++)
  267. {
  268. MemberItem memberItem = new MemberItem();
  269. memberItem.DisplayText = this.findNodeResult.Nodes[n].Text;
  270. memberItem.Tag = this.findNodeResult.Nodes[n].Tag;
  271.  
  272. if ( this.findNodeResult.Nodes[n].Tag != null )
  273. {
  274. System.Diagnostics.Debug.WriteLine(this.findNodeResult.Nodes[n].Tag.GetType().ToString());
  275. }
  276.  
  277. items[n] = memberItem;
  278. }
  279. Array.Sort(items);
  280.  
  281. for (int n=0;n < items.Length;n++)
  282. {
  283. int imageindex = 0;
  284.  
  285. if ( items[n].Tag != null )
  286. {
  287. // Default to method (contains text for parameters)
  288. imageindex = 2;
  289. if ( items[n].Tag is MemberTypes)
  290. {
  291. MemberTypes memberType = (MemberTypes) items[n].Tag;
  292.  
  293. switch ( memberType )
  294. {
  295. case MemberTypes.Custom:
  296. imageindex = 1;
  297. break;
  298. case MemberTypes.Property:
  299. imageindex = 3;
  300. break;
  301. case MemberTypes.Event:
  302. imageindex = 4;
  303. break;
  304. }
  305. }
  306. }
  307.  
  308. this.listBoxAutoComplete.Items.Add(new GListBoxItem(items[n].DisplayText,imageindex) );
  309. }
  310. }
  311. }
  312. }
  313.  
  314. return result;
  315. }
  316.  
  317. /// 
  318. /// Autofills the selected item in the member listbox, by
  319. /// taking everything before and after the "." in the richtextbox,
  320. /// and appending the word in the middle.
  321. /// 
  322. private void selectItem()
  323. {
  324. if ( this.wordMatched )
  325. {
  326. int selstart = this.richTextBox1.SelectionStart;
  327. int prefixend = this.richTextBox1.SelectionStart - typed.Length;
  328. int suffixstart = this.richTextBox1.SelectionStart + typed.Length;
  329.  
  330. if ( suffixstart >= this.richTextBox1.Text.Length )
  331. {
  332. suffixstart = this.richTextBox1.Text.Length;
  333. }
  334.  
  335. string prefix = this.richTextBox1.Text.Substring(0,prefixend);
  336. string fill = this.listBoxAutoComplete.SelectedItem.ToString();
  337. string suffix = this.richTextBox1.Text.Substring(suffixstart,this.richTextBox1.Text.Length - suffixstart);
  338.  
  339. this.richTextBox1.Text = prefix + fill + suffix;
  340. this.richTextBox1.SelectionStart = prefix.Length + fill.Length;
  341. }
  342. }
  343.  
  344. /// 
  345. /// Searches backwards from the current caret position, until
  346. /// a space or newline is found.
  347. /// 
  348. /// The previous word from the carret position
  349. private string getLastWord()
  350. {
  351. string word = "";
  352.  
  353. int pos = this.richTextBox1.SelectionStart;
  354. if ( pos > 1 )
  355. {
  356.  
  357. string tmp = "";
  358. char f = new char();
  359. while ( f != ' ' && f != 10 && pos > 0 )
  360. {
  361. pos--;
  362. tmp = this.richTextBox1.Text.Substring(pos,1);
  363. f = (char) tmp[0];
  364. word += f; 
  365. }
  366.  
  367. char[] ca = word.ToCharArray();
  368. Array.Reverse( ca );
  369. word = new String( ca );
  370.  
  371. }
  372. return word.Trim();
  373.  
  374. }
  375. #endregion
  376.  
  377. private void FormMain_Load(object sender, EventArgs e)
  378. {
  379. readAssembly();
  380.  
  381.  
  382. }
  383. }
  384.  












Raja
May 31 '07 #1
1 1933
Plater
7,872 Expert 4TB
So you wish to populate the autocomplete section of a listbox from a hashtable you have created by parsing .dll files for namespaces/classes and the like?
Could you not just keep passing more .dll locations and adding to your hashtable?
Jun 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Foehammer | last post by:
Hello, I'm trying to load an assembly dynamically using an app domain. This is a proof-of-concept for a larger project, so please excuse the lame class names. TestLib is the dll where all the...
1
by: BillyMac | last post by:
Hello I emply a "plug-in" architecture for a .NET Windows service. At OnStart, the service browses for DLL's in in sub-folders and loads them dyanamically using Assembly.LoadFrom() The...
9
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the...
6
by: Pete Davis | last post by:
I'm confused about what precisely the limitations are on loading plugins in separate app domains. In all my previous apps that supported plugins, I've loaded them into the same domain as the app,...
4
by: Barry Kelly | last post by:
I'm designing an application framework which will, amongst other things, live in an assembly hosted in the ASP.NET worker process, servicing webservice requests. Here's the scenario: APPFX is...
1
by: John F | last post by:
Hello all, When dynamically loading classes through reflection using Assembly.LoadFrom I have the following questions: 1) Once you load an assembly it doesn't appear you can unload it. If you...
2
by: jnick | last post by:
I have the predicament of having to load several assemblies on the fly and when I do so, I get an exception stating that one of the referenced assemblies cannot be found. Is there any way to...
1
by: =?Windows-1252?Q?Tor_B=E5dshaug?= | last post by:
BlankHi, I am having trouble loading assemblies from the database in my ASP.NET app. I have a default.aspx in my app that is served from a database via a custom virtual path provider. This works...
8
by: =?Utf-8?B?TWFyaw==?= | last post by:
We've got a wierd failure happening on just one machine. One part of our product uses a 3rd party search implementation (dtSearch). DtSearch has a native core (dten600.dll), late-bound, and a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.