473,390 Members | 1,091 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,390 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 1939
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.