Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GenerateUserDocumentationProcessor.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
5 using System.Text.RegularExpressions;
6 using System.Xml.Linq;
7 
8 namespace SiliconStudio.AssemblyProcessor
9 {
11  {
12  private readonly string inputFile;
13 
14  public GenerateUserDocumentationProcessor(string inputFile)
15  {
16  if (inputFile == null) throw new ArgumentNullException("inputFile");
17  this.inputFile = inputFile;
18  }
19 
20  public bool Process(AssemblyProcessorContext context)
21  {
22  var basePath = Path.Combine(Path.GetDirectoryName(inputFile) ?? "", Path.GetFileNameWithoutExtension(inputFile) ?? "");
23  var xmlFile = basePath + ".xml";
24  var targetFile = basePath + ".usrdoc";
25 
26  // No xml documentation file available, stop here.
27  if (!File.Exists(xmlFile))
28  return false;
29 
30  var result = new Dictionary<string, string>();
31 
32  var document = XElement.Load(xmlFile);
33  foreach (var member in document.Descendants("member"))
34  {
35  var nameAttribute = member.Attribute("name");
36  if (nameAttribute == null)
37  continue;
38  string key = nameAttribute.Value;
39 
40  string userdoc = null;
41  foreach (var userdocElement in member.Descendants("userdoc"))
42  {
43  if (userdoc != null)
44  {
45  LogLine("Warning: the member {0} has multiple userdoc, only the first one will be used.", key);
46  break;
47  }
48  if (userdocElement.Descendants().Any())
49  {
50  LogLine("Warning: the userdoc of member {0} has descendant nodes, which is not supported.", key);
51  break;
52  }
53  userdoc = userdocElement.Value;
54  userdoc = userdoc.Replace('\t', ' ').Replace('\r', ' ').Replace('\n', ' ').Trim();
55  // Removes double space.
56  var regex = new Regex(@"[ ]{2,}", RegexOptions.None);
57  userdoc = regex.Replace(userdoc, @" ");
58  }
59  if (userdoc != null)
60  {
61  result.Add(key, userdoc);
62  }
63  }
64 
65  using (var writer = new StreamWriter(targetFile))
66  {
67  foreach (var entry in result)
68  {
69  writer.WriteLine("{0}={1}", entry.Key, entry.Value);
70  }
71  }
72 
73  return true;
74  }
75 
76  private static void LogLine(string format, params object[] args)
77  {
78  Console.WriteLine(format, args);
79  }
80  }
81 }
System.IO.File File
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175