/WikiDocGenerator/MainWindow.xaml.cs

http://yet-another-music-application.googlecode.com/ · C# · 892 lines · 657 code · 115 blank · 120 comment · 184 complexity · aa11eaead4db299a9e10516ab9f76858 MD5 · raw file

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.IO;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Xml;
  17. using Microsoft.Win32;
  18. namespace WikiDocGenerator
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. public partial class MainWindow : Window
  24. {
  25. #region Members
  26. List<Class> classes = new List<Class>();
  27. List<Enum> enums = new List<Enum>();
  28. List<Delegate> delegates = new List<Delegate>();
  29. #endregion
  30. #region Constructor
  31. /// <summary>
  32. ///
  33. /// </summary>
  34. public MainWindow()
  35. {
  36. //InitializeComponent();
  37. //Match m2 = r.Match(text2);
  38. //Match m3 = r.Match(text3);
  39. //MessageBox.Show("Match on 1: " + m1.Success + "\nMatch on 2: " + m2.Success + "\nMatch on 3: " + m3.Success);
  40. //Close();
  41. string file = @"H:\Development\Stoffi\trunk\Application\bin\Debug\Stoffi.XML";
  42. Read(file);
  43. Close();
  44. }
  45. #endregion
  46. #region Methods
  47. #region Private
  48. /// <summary>
  49. ///
  50. /// </summary>
  51. /// <param name="filename"></param>
  52. private void Read(string filename)
  53. {
  54. XmlTextReader xmlReader = new XmlTextReader(filename);
  55. xmlReader.WhitespaceHandling = WhitespaceHandling.None;
  56. xmlReader.Read();
  57. xmlReader.Read();
  58. xmlReader.Read();
  59. xmlReader.Skip();
  60. int i = 0;
  61. if (xmlReader.Name == "members")
  62. {
  63. List<Entity> entities = new List<Entity>();
  64. Hashtable classTable = new Hashtable();
  65. xmlReader.Read();
  66. while (!(xmlReader.Name == "members" && xmlReader.NodeType == XmlNodeType.EndElement))
  67. {
  68. i++;
  69. ReadMember(xmlReader, entities);
  70. xmlReader.Read();
  71. //if (i > 3) break;
  72. }
  73. foreach (Entity e in entities)
  74. {
  75. if (e.Name.StartsWith("XamlGeneratedNamespace") ||
  76. e.Name.StartsWith("Stoffi.Properties.")) continue;
  77. if (e is Class)
  78. {
  79. string[] name = ParseName(e.Name);
  80. e.Name = name[0];
  81. classTable[name[0]] = e;
  82. }
  83. }
  84. foreach (Entity e in entities)
  85. {
  86. if (e.Name.StartsWith("XamlGeneratedNamespace") ||
  87. e.Name.StartsWith("Stoffi.Properties.")) continue;
  88. if (e is Method)
  89. {
  90. string[] name = ParseName(e.Name, true);
  91. e.Name = name[1];
  92. Class c = classTable[name[0]] as Class;
  93. c.Methods.Add(e as Method);
  94. }
  95. else if (e is Delegate)
  96. {
  97. string[] name = ParseName(e.Name, true);
  98. if (name[1] == null)
  99. {
  100. e.Name = name[0];
  101. delegates.Add(e as Delegate);
  102. }
  103. else
  104. {
  105. e.Name = name[1];
  106. Class c = classTable[name[0]] as Class;
  107. c.Delegates.Add(e as Delegate);
  108. }
  109. }
  110. else if (e is Event)
  111. {
  112. string[] name = ParseName(e.Name, true);
  113. e.Name = name[1];
  114. Class c = classTable[name[0]] as Class;
  115. c.Events.Add(e as Event);
  116. }
  117. else if (e is Field)
  118. {
  119. string[] name = ParseName(e.Name, true);
  120. e.Name = name[1];
  121. Class c = classTable[name[0]] as Class;
  122. c.Fields.Add(e as Field);
  123. }
  124. else if (e is Property)
  125. {
  126. string[] name = ParseName(e.Name, true);
  127. e.Name = name[1];
  128. Class c = classTable[name[0]] as Class;
  129. c.Properties.Add(e as Property);
  130. }
  131. else if (!(e is Class))
  132. {
  133. Console.WriteLine("Unknown type of entity: " + e.Name);
  134. }
  135. }
  136. foreach (DictionaryEntry o in classTable)
  137. {
  138. Class c = o.Value as Class;
  139. if (c.Fields.Count > 0 && c.Methods.Count == 0 && c.Events.Count == 0 && c.Properties.Count == 0)
  140. {
  141. Enum e = new Enum();
  142. e.Name = c.Name;
  143. e.Summary = c.Summary;
  144. e.SeeAlsos = c.SeeAlsos;
  145. e.Remarks = c.Remarks;
  146. foreach (Field f in c.Fields)
  147. {
  148. Value v = new Value();
  149. v.Name = f.Name;
  150. v.Summary = f.Summary;
  151. v.SeeAlsos = f.SeeAlsos;
  152. v.Remarks = f.Remarks;
  153. e.Values.Add(v);
  154. }
  155. enums.Add(e);
  156. }
  157. else
  158. {
  159. foreach (Method m in c.Methods)
  160. {
  161. if (m.Name.StartsWith("#cctor") || m.Name.StartsWith("#ctor"))
  162. c.Constructor = m;
  163. else if (m.Name == "Finalize")
  164. c.Destructor = m;
  165. }
  166. c.Methods.Remove(c.Constructor);
  167. c.Methods.Remove(c.Destructor);
  168. classes.Add(c);
  169. }
  170. }
  171. Generate();
  172. }
  173. else
  174. {
  175. Console.WriteLine("Expected element <members> but got <" + xmlReader.Name + "> instead");
  176. }
  177. }
  178. /// <summary>
  179. ///
  180. /// </summary>
  181. /// <param name="name"></param>
  182. /// <param name="hasParent"></param>
  183. /// <returns></returns>
  184. private string[] ParseName(string name, bool hasParent = false)
  185. {
  186. //if (name.StartsWith("Stoffi.Utilities."))
  187. // name = name.Remove(0, "Stoffi.Utilities.".Length);
  188. if (name.StartsWith("Stoffi."))
  189. name = name.Remove(0, "Stoffi.".Length);
  190. string[] ret = new string[2];
  191. int p = name.IndexOf('.');
  192. if (hasParent && p >= 0)
  193. {
  194. ret[0] = name.Substring(0, p);
  195. ret[1] = name.Substring(p+1);
  196. }
  197. else ret[0] = name;
  198. return ret;
  199. }
  200. /// <summary>
  201. ///
  202. /// </summary>
  203. /// <param name="xmlReader"></param>
  204. /// <param name="entities"></param>
  205. private void ReadMember(XmlTextReader xmlReader, List<Entity> entities)
  206. {
  207. if (xmlReader.Name == "member" && xmlReader.NodeType == XmlNodeType.Element)
  208. {
  209. string[] nameFields = xmlReader.GetAttribute(0).Split(':');
  210. Entity e;
  211. Entity e1 = new Delegate();
  212. if (nameFields[0] == "F")
  213. e = new Field();
  214. else if (nameFields[0] == "T")
  215. {
  216. e = new Class();
  217. }
  218. else if (nameFields[0] == "E")
  219. e = new Event();
  220. else if (nameFields[0] == "M")
  221. e = new Method();
  222. else if (nameFields[0] == "P")
  223. e = new Property();
  224. else
  225. {
  226. Console.WriteLine("Member '" + nameFields[1] + "' is of unknown type: " + nameFields[0]);
  227. return;
  228. }
  229. e.Name = nameFields[1];
  230. //Console.WriteLine("####### MEMBER: " + e.Name + " ###############");
  231. xmlReader.Read();
  232. while (!(xmlReader.Name == "member" && xmlReader.NodeType == XmlNodeType.EndElement))
  233. {
  234. if (xmlReader.NodeType == XmlNodeType.Element)
  235. {
  236. string tag = xmlReader.Name;
  237. string value = "";
  238. string name = "";
  239. if (xmlReader.HasAttributes)
  240. name = xmlReader.GetAttribute(0);
  241. value = ReadTag(xmlReader);
  242. if (tag.ToLower() == "summary")
  243. e.Summary = value;
  244. else if (tag.ToLower() == "seealso")
  245. e.SeeAlsos.Add(value);
  246. else if (tag.ToLower() == "remarks")
  247. e.Remarks.Add(value);
  248. else if (tag.ToLower() == "param" && e is Method)
  249. ((Method)e).Params[name] = value;
  250. else if (tag.ToLower() == "typeparam" && e is Method)
  251. ((Method)e).TypeParam = value;
  252. else if (tag.ToLower() == "returns" && e is Method)
  253. ((Method)e).Return = value;
  254. else if (tag.ToLower() == "param" && e is Delegate)
  255. ((Delegate)e).Params[name] = value;
  256. else if (tag.ToLower() == "typeparam" && e is Delegate)
  257. ((Delegate)e).TypeParam = value;
  258. else if (tag.ToLower() == "returns" && e is Delegate)
  259. ((Delegate)e).Return = value;
  260. else if (tag.ToLower() == "param" && e is Class)
  261. {
  262. e1.Name = e.Name;
  263. e1.Summary = e.Summary;
  264. e1.SeeAlsos = e.SeeAlsos;
  265. e1.Remarks = e.Remarks;
  266. e = e1;
  267. ((Delegate)e).Params[name] = value;
  268. }
  269. else if (tag.ToLower() == "typeparam" && e is Class)
  270. {
  271. e1.Name = e.Name;
  272. e1.Summary = e.Summary;
  273. e1.SeeAlsos = e.SeeAlsos;
  274. e1.Remarks = e.Remarks;
  275. e = e1;
  276. ((Delegate)e).TypeParam = value;
  277. }
  278. else if (tag.ToLower() == "returns" && e is Class)
  279. {
  280. e1.Name = e.Name;
  281. e1.Summary = e.Summary;
  282. e1.SeeAlsos = e.SeeAlsos;
  283. e1.Remarks = e.Remarks;
  284. e = e1;
  285. ((Delegate)e).Return = value;
  286. }
  287. else
  288. Console.WriteLine(nameFields[1] + " has invalid member: " + tag + " = " + value);
  289. }
  290. xmlReader.Read();
  291. }
  292. entities.Add(e);
  293. }
  294. else
  295. {
  296. Console.WriteLine("Expected element <member> but got <" + xmlReader.Name + "> instead");
  297. }
  298. }
  299. /// <summary>
  300. ///
  301. /// </summary>
  302. /// <param name="xmlReader"></param>
  303. /// <returns></returns>
  304. private string ReadTag(XmlTextReader xmlReader)
  305. {
  306. string name = xmlReader.Name;
  307. string value = "";
  308. //Console.WriteLine("Reading tag: " + name + "\t\tEmpty: " + xmlReader.IsEmptyElement);
  309. if (xmlReader.IsEmptyElement)
  310. {
  311. if (xmlReader.HasAttributes)
  312. value = xmlReader.GetAttribute(0);
  313. }
  314. else
  315. {
  316. xmlReader.Read();
  317. while (!(xmlReader.Name == name && xmlReader.NodeType == XmlNodeType.EndElement))
  318. {
  319. if (xmlReader.NodeType == XmlNodeType.Text)
  320. value += xmlReader.Value;
  321. else if (xmlReader.NodeType == XmlNodeType.Element)
  322. {
  323. if (xmlReader.IsEmptyElement)
  324. {
  325. value += "<" + xmlReader.Name;
  326. if (xmlReader.HasAttributes)
  327. while (xmlReader.MoveToNextAttribute())
  328. value += String.Format(" {0}=\"{1}\"", xmlReader.Name, xmlReader.Value);
  329. value += "/>";
  330. }
  331. else
  332. {
  333. value += "<" + xmlReader.Name + ">";
  334. value += ReadTag(xmlReader);
  335. value += "</" + xmlReader.Name + ">";
  336. }
  337. }
  338. else if (xmlReader.NodeType == XmlNodeType.EndElement)
  339. {
  340. value += "</" + xmlReader.Name + ">";
  341. }
  342. xmlReader.Read();
  343. }
  344. }
  345. return value;
  346. }
  347. /// <summary>
  348. ///
  349. /// </summary>
  350. private void Generate()
  351. {
  352. foreach (Class c in classes)
  353. {
  354. Console.WriteLine("Go: " + c.Name);
  355. if (c.Name == "YouTubePlayerInterface")
  356. Console.WriteLine("Stop!");
  357. Directory.CreateDirectory("output");
  358. StreamWriter sw = File.CreateText(Path.Combine("output", c.Name + "Class.wiki"));
  359. sw.WriteLine("#summary Class specification of " + c.Name);
  360. sw.WriteLine("#labels Doc-Class");
  361. sw.WriteLine("= Overview =");
  362. sw.WriteLine(FixInformation(c, c, false));
  363. sw.WriteLine("<wiki:toc/>");
  364. sw.WriteLine("----");
  365. if (c.Constructor != null)
  366. {
  367. sw.WriteLine("= Constructor =");
  368. sw.WriteLine("||`" + FixMethodName(c.Name, c.Constructor.Name, c.Constructor.Params) + "`||");
  369. sw.WriteLine("");
  370. foreach (DictionaryEntry o in c.Constructor.Params)
  371. sw.WriteLine(" _" + (o.Key as string) + ": " + (o.Value as string) + "_\n");
  372. sw.WriteLine(FixInformation(c, c.Constructor));
  373. }
  374. if (c.Destructor != null)
  375. {
  376. sw.WriteLine("= Destructor =");
  377. sw.WriteLine("||`" + FixMethodName(c.Name, c.Destructor.Name, c.Destructor.Params) + "`||");
  378. foreach (DictionaryEntry o in c.Destructor.Params)
  379. sw.WriteLine(" _" + (o.Key as string) + ": " + (o.Value as string) + "_\n");
  380. sw.WriteLine(FixInformation(c, c.Destructor));
  381. }
  382. if (c.Fields.Count > 0 || c.Properties.Count > 0)
  383. {
  384. sw.WriteLine("= Members =");
  385. if (c.Fields.Count > 0)
  386. {
  387. sw.WriteLine("== Fields ==");
  388. sw.WriteLine("");
  389. foreach (Field f in c.Fields)
  390. {
  391. sw.WriteLine("===" + EscapeCamelLink(f.Name) + "===");
  392. sw.WriteLine("");
  393. sw.WriteLine(FixInformation(c, f));
  394. }
  395. }
  396. if (c.Properties.Count > 0)
  397. {
  398. sw.WriteLine("== Properties ==");
  399. sw.WriteLine("");
  400. foreach (Property p in c.Properties)
  401. {
  402. sw.WriteLine("===" + EscapeCamelLink(p.Name) + "===");
  403. sw.WriteLine("");
  404. sw.WriteLine(FixInformation(c, p));
  405. }
  406. }
  407. }
  408. if (c.Methods.Count > 0)
  409. {
  410. sw.WriteLine("= Methods =");
  411. sw.WriteLine("");
  412. foreach (Method m in c.Methods)
  413. {
  414. sw.WriteLine("===" + EscapeCamelLink(StripMethodName(m.Name)) + "===");
  415. sw.WriteLine("");
  416. sw.WriteLine("||`" + FixMethodName(c.Name, m.Name, m.Params) + "`||");
  417. sw.WriteLine("");
  418. foreach (DictionaryEntry o in m.Params)
  419. sw.WriteLine(" _" + (o.Key as string) + ": " + (o.Value as string) + "_\n");
  420. sw.WriteLine(FixInformation(c, m));
  421. }
  422. }
  423. if (c.Delegates.Count > 0)
  424. {
  425. sw.WriteLine("= Delegates =");
  426. sw.WriteLine("");
  427. foreach (Delegate d in c.Delegates)
  428. {
  429. sw.WriteLine("===" + EscapeCamelLink(StripMethodName(d.Name)) + "===");
  430. sw.WriteLine("");
  431. sw.WriteLine("||`" + FixMethodName(c.Name, d.Name, d.Params) + "`||");
  432. sw.WriteLine("");
  433. foreach (DictionaryEntry o in d.Params)
  434. sw.WriteLine(" _" + (o.Key as string) + ": " + (o.Value as string) + "_\n");
  435. sw.WriteLine(FixInformation(c, d));
  436. }
  437. }
  438. if (c.Events.Count > 0)
  439. {
  440. sw.WriteLine("= Events =");
  441. sw.WriteLine("");
  442. foreach (Event e in c.Events)
  443. {
  444. sw.WriteLine("===" + EscapeCamelLink(e.Name) + "===");
  445. sw.WriteLine("");
  446. sw.WriteLine(FixInformation(c, e));
  447. }
  448. }
  449. sw.Close();
  450. }
  451. foreach (Enum e in enums)
  452. {
  453. Directory.CreateDirectory("output");
  454. StreamWriter sw = File.CreateText(Path.Combine("output", e.Name + "Enum.wiki"));
  455. sw.WriteLine("#summary Enum specification of " + e.Name);
  456. sw.WriteLine("#labels Doc-Enum");
  457. sw.WriteLine("= Overview =");
  458. sw.WriteLine(FixInformation(e, e, false));
  459. sw.WriteLine("<wiki:toc/>");
  460. sw.WriteLine("----");
  461. if (e.Values.Count > 0)
  462. {
  463. sw.WriteLine("= Values =");
  464. sw.WriteLine("");
  465. foreach (Value v in e.Values)
  466. {
  467. sw.WriteLine("==" + v.Name + "==");
  468. sw.WriteLine(FixInformation(e, v));
  469. }
  470. }
  471. sw.Close();
  472. }
  473. foreach (Delegate e in delegates)
  474. {
  475. Directory.CreateDirectory("output");
  476. StreamWriter sw = File.CreateText(Path.Combine("output", e.Name + "Delegate.wiki"));
  477. sw.WriteLine("#summary Delegate specification of " + e.Name);
  478. sw.WriteLine("#labels Doc-Delegate");
  479. sw.WriteLine("= Overview =");
  480. sw.WriteLine(FixInformation(e, e, false));
  481. sw.WriteLine("<wiki:toc/>");
  482. sw.WriteLine("----");
  483. sw.WriteLine("");
  484. sw.WriteLine("||`" + FixMethodName("", e.Name, e.Params) + "`||");
  485. sw.WriteLine("");
  486. foreach (DictionaryEntry o in e.Params)
  487. sw.WriteLine(" _" + (o.Key as string) + ": " + (o.Value as string) + "_\n");
  488. sw.Close();
  489. }
  490. }
  491. /// <summary>
  492. ///
  493. /// </summary>
  494. /// <param name="str"></param>
  495. /// <returns></returns>
  496. private string EscapeCamelLink(string str)
  497. {
  498. if (HasCamelCase(str)) return "!" + str;
  499. else return str;
  500. }
  501. /// <summary>
  502. ///
  503. /// </summary>
  504. /// <param name="p"></param>
  505. /// <param name="e"></param>
  506. /// <param name="returnToTop"></param>
  507. /// <returns></returns>
  508. private string FixInformation(Entity p, Entity e, bool returnToTop = true)
  509. {
  510. string txt = ParseForLinks(FixSummary(e.Summary)) + "\n\n";
  511. if (e.Remarks.Count > 0) txt += "\n";
  512. foreach (string remark in e.Remarks)
  513. txt += " _Remark: " + ParseForLinks(remark) + "_\n\n";
  514. if (e.SeeAlsos.Count > 0) txt += "\n";
  515. foreach (string seealso in e.SeeAlsos)
  516. txt += " _See also: " + ParseSeeAlso(seealso) + "_\n\n";
  517. if (returnToTop)
  518. {
  519. txt += "[" + p.Name + (p is Class ? "Class":"Enum") + "#Overview Return to top]\n\n<br/>";
  520. }
  521. return txt;
  522. }
  523. /// <summary>
  524. ///
  525. /// </summary>
  526. /// <param name="str"></param>
  527. /// <returns></returns>
  528. private bool HasCamelCase(string str)
  529. {
  530. string pat = @"^[A-Z]+.*[a-z]+.*[A-Z].*[a-z]+";
  531. Regex r = new Regex(pat, RegexOptions.None);
  532. Match m = r.Match(str);
  533. return m.Success;
  534. }
  535. /// <summary>
  536. ///
  537. /// </summary>
  538. /// <param name="summary"></param>
  539. /// <returns></returns>
  540. private string FixSummary(string summary)
  541. {
  542. summary = summary.Trim();
  543. summary = summary.Replace(" ", "");
  544. summary = summary.Replace("1)", " #");
  545. summary = summary.Replace("2)", " #");
  546. summary = summary.Replace("3)", " #");
  547. summary = summary.Replace("4)", " #");
  548. summary = summary.Replace("5)", " #");
  549. summary = summary.Replace("6)", " #");
  550. summary = summary.Replace("7)", " #");
  551. summary = summary.Replace("8)", " #");
  552. summary = summary.Replace("9)", " #");
  553. return summary;
  554. }
  555. /// <summary>
  556. ///
  557. /// </summary>
  558. /// <param name="cname"></param>
  559. /// <param name="method"></param>
  560. /// <param name="args"></param>
  561. /// <returns></returns>
  562. private string FixMethodName(string cname, string method, Hashtable args)
  563. {
  564. string name = method;
  565. string arguments = "";
  566. if (name.EndsWith(")"))
  567. {
  568. List<string> pnames = new List<string>();
  569. foreach (DictionaryEntry o in args)
  570. pnames.Add(o.Key as string);
  571. string paras = "";
  572. name = method.Substring(0, method.IndexOf('('));
  573. paras = method.Substring(method.IndexOf('(') + 1);
  574. paras = paras.Substring(0, paras.Length - 1);
  575. string[] para = paras.Split(',');
  576. int i=0;
  577. foreach (string ptype in para)
  578. {
  579. arguments += ptype.Substring(ptype.LastIndexOf('.') + 1) + " " + pnames[i++] + ", ";
  580. }
  581. arguments = arguments.Substring(0, arguments.Length - 2);
  582. }
  583. return name.Replace("Finalize", "~" + cname).Replace("#cctor", cname).Replace("#ctor", cname) + "(" + arguments + ")";
  584. }
  585. /// <summary>
  586. ///
  587. /// </summary>
  588. /// <param name="mname"></param>
  589. /// <returns></returns>
  590. private string StripMethodName(string mname)
  591. {
  592. if (mname.Contains('(')) return mname.Substring(0, mname.IndexOf('('));
  593. else return mname;
  594. }
  595. /// <summary>
  596. ///
  597. /// </summary>
  598. /// <param name="str"></param>
  599. /// <returns></returns>
  600. private string ParseSeeAlso(string str)
  601. {
  602. if (!str.Contains(':')) return str;
  603. string type = str.Substring(0, str.IndexOf(':'));
  604. str = str.Substring(str.IndexOf(':')+1);
  605. if (str.Contains('(')) str = str.Substring(0, str.IndexOf('('));
  606. int i = str.LastIndexOf('.');
  607. if (i < 0) return str;
  608. string parent = str.Substring(0, i);
  609. string name = str.Substring(i + 1);
  610. if (parent.StartsWith("Stoffi.Utilities."))
  611. parent = parent.Remove(0, "Stoffi.Utilities.".Length);
  612. else if (parent.StartsWith("Stoffi."))
  613. parent = parent.Remove(0, "Stoffi.".Length);
  614. if (type == "T")
  615. {
  616. foreach (Class c in classes)
  617. if (c.Name == name) return "[" + c.Name + "Class " + name + "]";
  618. foreach (Enum e in enums)
  619. if (e.Name == name) return "[" + e.Name + "Enum " + name + "]";
  620. return "[" + parent + "." + name + " " + parent + "." + name + "]";
  621. }
  622. string lstr = name + " " + name;
  623. if (type == "M") lstr += "()";
  624. foreach (Class c in classes)
  625. if (c.Name == parent) return "[" + c.Name + "Class#" + lstr + "]";
  626. foreach (Enum e in enums)
  627. if (e.Name == parent) return "[" + e.Name + "Enum#" + lstr + "]";
  628. return "[" + parent + "." + name + " " + parent + "." + name + "]";
  629. }
  630. /// <summary>
  631. ///
  632. /// </summary>
  633. /// <param name="str"></param>
  634. /// <returns></returns>
  635. private string ParseForLinks(string str)
  636. {
  637. if (str.Length <= 0) return str;
  638. string ret = "";
  639. foreach (string word in str.Split(new char[3] { ' ', '.', ','}))
  640. {
  641. string parsedWord = Linkalize(word);
  642. if (parsedWord == word && HasCamelCase(parsedWord)) parsedWord = "!" + parsedWord;
  643. ret += " " + parsedWord;
  644. }
  645. return ret.Substring(1);
  646. }
  647. /// <summary>
  648. ///
  649. /// </summary>
  650. /// <param name="str"></param>
  651. /// <returns></returns>
  652. private string Linkalize(string str)
  653. {
  654. foreach (Class c in classes)
  655. {
  656. if (c.Name == str) return "[" + c.Name + "Class " + str + "]";
  657. foreach (Field f in c.Fields)
  658. if (f.Name == str) return "[" + c.Name + "Class#" + f.Name + " " + str + "]";
  659. foreach (Property p in c.Properties)
  660. if (p.Name == str) return "[" + c.Name + "Class#" + p.Name + " " + str + "]";
  661. foreach (Method m in c.Methods)
  662. if (StripMethodName(m.Name) == str) return "[" + c.Name + "Class#" + StripMethodName(m.Name) + " " + str + "]";
  663. foreach (Event e in c.Events)
  664. if (e.Name == str) return "[" + c.Name + "Class#" + e.Name + " " + str + "]";
  665. }
  666. foreach (Enum e in enums)
  667. {
  668. if (e.Name == str) return "[" + e.Name + "Enum " + str + "]";
  669. foreach (Value v in e.Values)
  670. if (v.Name == str) return "[" + e.Name + "Enum#" + v.Name + " " + str + "]";
  671. }
  672. return str;
  673. }
  674. #endregion
  675. #region Event handlers
  676. /// <summary>
  677. ///
  678. /// </summary>
  679. /// <param name="sender"></param>
  680. /// <param name="e"></param>
  681. private void StartButton_Click(object sender, RoutedEventArgs e)
  682. {
  683. OpenFileDialog dlg = new OpenFileDialog();
  684. Nullable<bool> result = dlg.ShowDialog();
  685. if (result == true)
  686. {
  687. Read(dlg.FileName);
  688. }
  689. }
  690. #endregion
  691. #endregion
  692. #region Classes
  693. /// <summary>
  694. ///
  695. /// </summary>
  696. class Entity
  697. {
  698. #region Members
  699. public string Name;
  700. public string Summary;
  701. public List<string> SeeAlsos = new List<string>();
  702. public List<string> Remarks = new List<string>();
  703. #endregion
  704. }
  705. /// <summary>
  706. ///
  707. /// </summary>
  708. class Class : Entity
  709. {
  710. #region Members
  711. public List<Property> Properties = new List<Property>();
  712. public Method Constructor = null;
  713. public Method Destructor = null;
  714. public List<Method> Methods = new List<Method>();
  715. public List<Delegate> Delegates = new List<Delegate>();
  716. public List<Event> Events = new List<Event>();
  717. public List<Field> Fields = new List<Field>();
  718. #endregion
  719. }
  720. /// <summary>
  721. ///
  722. /// </summary>
  723. class Field : Entity
  724. {
  725. }
  726. /// <summary>
  727. ///
  728. /// </summary>
  729. class Event : Entity
  730. {
  731. }
  732. /// <summary>
  733. ///
  734. /// </summary>
  735. class Property : Entity
  736. {
  737. }
  738. /// <summary>
  739. ///
  740. /// </summary>
  741. class Method : Entity
  742. {
  743. #region Members
  744. public string Return;
  745. public string TypeParam;
  746. public Hashtable Params = new Hashtable();
  747. #endregion
  748. }
  749. /// <summary>
  750. ///
  751. /// </summary>
  752. class Enum : Entity
  753. {
  754. #region Members
  755. public List<Value> Values = new List<Value>();
  756. #endregion
  757. }
  758. /// <summary>
  759. ///
  760. /// </summary>
  761. class Value : Entity
  762. {
  763. }
  764. /// <summary>
  765. ///
  766. /// </summary>
  767. class Delegate : Entity
  768. {
  769. #region Members
  770. public string Return;
  771. public string TypeParam;
  772. public Hashtable Params = new Hashtable();
  773. #endregion
  774. }
  775. #endregion
  776. }
  777. }