Fortunes.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. // ------------------------------------------------------------------------------
  2. // <auto-generated>
  3. // This code was generated by a tool.
  4. // Runtime Version: 10.0.0.0
  5. //
  6. // Changes to this file may cause incorrect behavior and will be lost if
  7. // the code is regenerated.
  8. // </auto-generated>
  9. // ------------------------------------------------------------------------------
  10. namespace Revenj.Bench
  11. {
  12. using System;
  13. #line 1 "D:\Projects\FrameworkBenchmarks\frameworks\CSharp\revenj\Revenj.Bench\Fortunes.tt"
  14. [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "10.0.0.0")]
  15. public partial class Fortunes : FortunesBase
  16. {
  17. public virtual string TransformText()
  18. {
  19. this.Write("\n");
  20. this.Write("\n");
  21. this.Write("\n<!DOCTYPE html>\n<html>\n<head><title>Fortunes</title></head>\n<body><table><tr><th" +
  22. ">id</th><th>message</th></tr>\n");
  23. #line 1 "D:\Projects\FrameworkBenchmarks\frameworks\CSharp\revenj\Revenj.Bench\Fortunes.tt"
  24. for (var i=0; i<fortunes.Count;i++) {
  25. var f = fortunes[i];
  26. #line default
  27. #line hidden
  28. this.Write("\n<tr><td>");
  29. #line 1 "D:\Projects\FrameworkBenchmarks\frameworks\CSharp\revenj\Revenj.Bench\Fortunes.tt"
  30. Show(f.Key);
  31. #line default
  32. #line hidden
  33. this.Write("</td><td>");
  34. #line 1 "D:\Projects\FrameworkBenchmarks\frameworks\CSharp\revenj\Revenj.Bench\Fortunes.tt"
  35. Show(f.Value);
  36. #line default
  37. #line hidden
  38. this.Write("</td></tr>\n");
  39. #line 1 "D:\Projects\FrameworkBenchmarks\frameworks\CSharp\revenj\Revenj.Bench\Fortunes.tt"
  40. }
  41. #line default
  42. #line hidden
  43. this.Write("\n</table>\n</body>\n</html>");
  44. return this.GenerationEnvironment.ToString();
  45. }
  46. #line 1 "D:\Projects\FrameworkBenchmarks\frameworks\CSharp\revenj\Revenj.Bench\Fortunes.tt"
  47. private global::System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<int, string>> _fortunesField;
  48. /// <summary>
  49. /// Access the fortunes parameter of the template.
  50. /// </summary>
  51. private global::System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<int, string>> fortunes
  52. {
  53. get
  54. {
  55. return this._fortunesField;
  56. }
  57. }
  58. public virtual void Initialize()
  59. {
  60. if ((this.Errors.HasErrors == false))
  61. {
  62. bool fortunesValueAcquired = false;
  63. if (this.Session.ContainsKey("fortunes"))
  64. {
  65. if ((typeof(global::System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<int, string>>).IsAssignableFrom(this.Session["fortunes"].GetType()) == false))
  66. {
  67. this.Error("The type \'System.Collections.Generic.List<System.Collections.Generic.KeyValuePair" +
  68. "<int, string>>\' of the parameter \'fortunes\' did not match the type of the data p" +
  69. "assed to the template.");
  70. }
  71. else
  72. {
  73. this._fortunesField = ((global::System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<int, string>>)(this.Session["fortunes"]));
  74. fortunesValueAcquired = true;
  75. }
  76. }
  77. if ((fortunesValueAcquired == false))
  78. {
  79. object data = global::System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("fortunes");
  80. if ((data != null))
  81. {
  82. if ((typeof(global::System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<int, string>>).IsAssignableFrom(data.GetType()) == false))
  83. {
  84. this.Error("The type \'System.Collections.Generic.List<System.Collections.Generic.KeyValuePair" +
  85. "<int, string>>\' of the parameter \'fortunes\' did not match the type of the data p" +
  86. "assed to the template.");
  87. }
  88. else
  89. {
  90. this._fortunesField = ((global::System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<int, string>>)(data));
  91. }
  92. }
  93. }
  94. }
  95. }
  96. #line default
  97. #line hidden
  98. }
  99. #line default
  100. #line hidden
  101. #region Base class
  102. /// <summary>
  103. /// Base class for this transformation
  104. /// </summary>
  105. [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "10.0.0.0")]
  106. public class FortunesBase
  107. {
  108. #region Fields
  109. private global::System.Text.StringBuilder generationEnvironmentField;
  110. private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
  111. private global::System.Collections.Generic.List<int> indentLengthsField;
  112. private string currentIndentField = "";
  113. private bool endsWithNewline;
  114. private global::System.Collections.Generic.IDictionary<string, object> sessionField;
  115. #endregion
  116. #region Properties
  117. /// <summary>
  118. /// The string builder that generation-time code is using to assemble generated output
  119. /// </summary>
  120. protected System.Text.StringBuilder GenerationEnvironment
  121. {
  122. get
  123. {
  124. if ((this.generationEnvironmentField == null))
  125. {
  126. this.generationEnvironmentField = new global::System.Text.StringBuilder();
  127. }
  128. return this.generationEnvironmentField;
  129. }
  130. set
  131. {
  132. this.generationEnvironmentField = value;
  133. }
  134. }
  135. /// <summary>
  136. /// The error collection for the generation process
  137. /// </summary>
  138. public System.CodeDom.Compiler.CompilerErrorCollection Errors
  139. {
  140. get
  141. {
  142. if ((this.errorsField == null))
  143. {
  144. this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
  145. }
  146. return this.errorsField;
  147. }
  148. }
  149. /// <summary>
  150. /// A list of the lengths of each indent that was added with PushIndent
  151. /// </summary>
  152. private System.Collections.Generic.List<int> indentLengths
  153. {
  154. get
  155. {
  156. if ((this.indentLengthsField == null))
  157. {
  158. this.indentLengthsField = new global::System.Collections.Generic.List<int>();
  159. }
  160. return this.indentLengthsField;
  161. }
  162. }
  163. /// <summary>
  164. /// Gets the current indent we use when adding lines to the output
  165. /// </summary>
  166. public string CurrentIndent
  167. {
  168. get
  169. {
  170. return this.currentIndentField;
  171. }
  172. }
  173. /// <summary>
  174. /// Current transformation session
  175. /// </summary>
  176. public virtual global::System.Collections.Generic.IDictionary<string, object> Session
  177. {
  178. get
  179. {
  180. return this.sessionField;
  181. }
  182. set
  183. {
  184. this.sessionField = value;
  185. }
  186. }
  187. #endregion
  188. #region Transform-time helpers
  189. /// <summary>
  190. /// Write text directly into the generated output
  191. /// </summary>
  192. public void Write(string textToAppend)
  193. {
  194. if (string.IsNullOrEmpty(textToAppend))
  195. {
  196. return;
  197. }
  198. // If we're starting off, or if the previous text ended with a newline,
  199. // we have to append the current indent first.
  200. if (((this.GenerationEnvironment.Length == 0)
  201. || this.endsWithNewline))
  202. {
  203. this.GenerationEnvironment.Append(this.currentIndentField);
  204. this.endsWithNewline = false;
  205. }
  206. // Check if the current text ends with a newline
  207. if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
  208. {
  209. this.endsWithNewline = true;
  210. }
  211. // This is an optimization. If the current indent is "", then we don't have to do any
  212. // of the more complex stuff further down.
  213. if ((this.currentIndentField.Length == 0))
  214. {
  215. this.GenerationEnvironment.Append(textToAppend);
  216. return;
  217. }
  218. // Everywhere there is a newline in the text, add an indent after it
  219. textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
  220. // If the text ends with a newline, then we should strip off the indent added at the very end
  221. // because the appropriate indent will be added when the next time Write() is called
  222. if (this.endsWithNewline)
  223. {
  224. this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
  225. }
  226. else
  227. {
  228. this.GenerationEnvironment.Append(textToAppend);
  229. }
  230. }
  231. /// <summary>
  232. /// Write text directly into the generated output
  233. /// </summary>
  234. public void WriteLine(string textToAppend)
  235. {
  236. this.Write(textToAppend);
  237. this.GenerationEnvironment.AppendLine();
  238. this.endsWithNewline = true;
  239. }
  240. /// <summary>
  241. /// Write formatted text directly into the generated output
  242. /// </summary>
  243. public void Write(string format, params object[] args)
  244. {
  245. this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
  246. }
  247. /// <summary>
  248. /// Write formatted text directly into the generated output
  249. /// </summary>
  250. public void WriteLine(string format, params object[] args)
  251. {
  252. this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
  253. }
  254. /// <summary>
  255. /// Raise an error
  256. /// </summary>
  257. public void Error(string message)
  258. {
  259. System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
  260. error.ErrorText = message;
  261. this.Errors.Add(error);
  262. }
  263. /// <summary>
  264. /// Raise a warning
  265. /// </summary>
  266. public void Warning(string message)
  267. {
  268. System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
  269. error.ErrorText = message;
  270. error.IsWarning = true;
  271. this.Errors.Add(error);
  272. }
  273. /// <summary>
  274. /// Increase the indent
  275. /// </summary>
  276. public void PushIndent(string indent)
  277. {
  278. if ((indent == null))
  279. {
  280. throw new global::System.ArgumentNullException("indent");
  281. }
  282. this.currentIndentField = (this.currentIndentField + indent);
  283. this.indentLengths.Add(indent.Length);
  284. }
  285. /// <summary>
  286. /// Remove the last indent that was added with PushIndent
  287. /// </summary>
  288. public string PopIndent()
  289. {
  290. string returnValue = "";
  291. if ((this.indentLengths.Count > 0))
  292. {
  293. int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
  294. this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
  295. if ((indentLength > 0))
  296. {
  297. returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
  298. this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
  299. }
  300. }
  301. return returnValue;
  302. }
  303. /// <summary>
  304. /// Remove any indentation
  305. /// </summary>
  306. public void ClearIndent()
  307. {
  308. this.indentLengths.Clear();
  309. this.currentIndentField = "";
  310. }
  311. #endregion
  312. #region ToString Helpers
  313. /// <summary>
  314. /// Utility class to produce culture-oriented representation of an object as a string.
  315. /// </summary>
  316. public class ToStringInstanceHelper
  317. {
  318. private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
  319. /// <summary>
  320. /// Gets or sets format provider to be used by ToStringWithCulture method.
  321. /// </summary>
  322. public System.IFormatProvider FormatProvider
  323. {
  324. get
  325. {
  326. return this.formatProviderField ;
  327. }
  328. set
  329. {
  330. if ((value != null))
  331. {
  332. this.formatProviderField = value;
  333. }
  334. }
  335. }
  336. /// <summary>
  337. /// This is called from the compile/run appdomain to convert objects within an expression block to a string
  338. /// </summary>
  339. public string ToStringWithCulture(object objectToConvert)
  340. {
  341. if ((objectToConvert == null))
  342. {
  343. throw new global::System.ArgumentNullException("objectToConvert");
  344. }
  345. System.Type t = objectToConvert.GetType();
  346. System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
  347. typeof(System.IFormatProvider)});
  348. if ((method == null))
  349. {
  350. return objectToConvert.ToString();
  351. }
  352. else
  353. {
  354. return ((string)(method.Invoke(objectToConvert, new object[] {
  355. this.formatProviderField })));
  356. }
  357. }
  358. }
  359. private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
  360. public ToStringInstanceHelper ToStringHelper
  361. {
  362. get
  363. {
  364. return this.toStringHelperField;
  365. }
  366. }
  367. #endregion
  368. }
  369. #endregion
  370. }