TestHelpers.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. using CsvHelper.Configuration.Attributes;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using Xunit;
  12. using Xunit.Abstractions;
  13. using Xunit.Sdk;
  14. namespace Terminal.Gui;
  15. // This class enables test functions annotated with the [AutoInitShutdown] attribute to
  16. // automatically call Application.Init at start of the test and Application.Shutdown after the
  17. // test exits.
  18. //
  19. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  20. // as a pair, and b) all unit test functions should be atomic..
  21. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  22. public class AutoInitShutdownAttribute : BeforeAfterTestAttribute {
  23. readonly Type _driverType;
  24. /// <summary>
  25. /// Initializes a [AutoInitShutdown] attribute, which determines if/how Application.Init and
  26. /// Application.Shutdown are automatically called Before/After a test runs.
  27. /// </summary>
  28. /// <param name="autoInit">If true, Application.Init will be called Before the test runs.</param>
  29. /// <param name="autoShutdown">If true, Application.Shutdown will be called After the test runs.</param>
  30. /// <param name="consoleDriverType">
  31. /// Determines which ConsoleDriver (FakeDriver, WindowsDriver,
  32. /// CursesDriver, NetDriver) will be used when Application.Init is called. If null FakeDriver will be used.
  33. /// Only valid if <paramref name="autoInit"/> is true.
  34. /// </param>
  35. /// <param name="useFakeClipboard">
  36. /// If true, will force the use of <see cref="FakeDriver.FakeClipboard"/>.
  37. /// Only valid if <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
  38. /// </param>
  39. /// <param name="fakeClipboardAlwaysThrowsNotSupportedException">
  40. /// Only valid if <paramref name="autoInit"/> is true.
  41. /// Only valid if <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
  42. /// </param>
  43. /// <param name="fakeClipboardIsSupportedAlwaysTrue">
  44. /// Only valid if <paramref name="autoInit"/> is true.
  45. /// Only valid if <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
  46. /// </param>
  47. /// <param name="configLocation">
  48. /// Determines what config file locations <see cref="ConfigurationManager"/> will
  49. /// load from.
  50. /// </param>
  51. public AutoInitShutdownAttribute (bool autoInit = true,
  52. Type consoleDriverType = null,
  53. bool useFakeClipboard = true,
  54. bool fakeClipboardAlwaysThrowsNotSupportedException = false,
  55. bool fakeClipboardIsSupportedAlwaysTrue = false,
  56. ConfigurationManager.ConfigLocations configLocation = ConfigurationManager.ConfigLocations.DefaultOnly)
  57. {
  58. AutoInit = autoInit;
  59. CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
  60. _driverType = consoleDriverType ?? typeof (FakeDriver);
  61. FakeDriver.FakeBehaviors.UseFakeClipboard = useFakeClipboard;
  62. FakeDriver.FakeBehaviors.FakeClipboardAlwaysThrowsNotSupportedException = fakeClipboardAlwaysThrowsNotSupportedException;
  63. FakeDriver.FakeBehaviors.FakeClipboardIsSupportedAlwaysFalse = fakeClipboardIsSupportedAlwaysTrue;
  64. ConfigurationManager.Locations = configLocation;
  65. }
  66. bool AutoInit { get; }
  67. public override void Before (MethodInfo methodUnderTest)
  68. {
  69. Debug.WriteLine ($"Before: {methodUnderTest.Name}");
  70. if (AutoInit) {
  71. #if DEBUG_IDISPOSABLE
  72. // Clear out any lingering Responder instances from previous tests
  73. if (Responder.Instances.Count == 0) {
  74. Assert.Empty (Responder.Instances);
  75. } else {
  76. Responder.Instances.Clear ();
  77. }
  78. #endif
  79. Application.Init ((ConsoleDriver)Activator.CreateInstance (_driverType));
  80. }
  81. }
  82. public override void After (MethodInfo methodUnderTest)
  83. {
  84. Debug.WriteLine ($"After: {methodUnderTest.Name}");
  85. if (AutoInit) {
  86. Application.Shutdown ();
  87. #if DEBUG_IDISPOSABLE
  88. if (Responder.Instances.Count == 0) {
  89. Assert.Empty (Responder.Instances);
  90. } else {
  91. Responder.Instances.Clear ();
  92. }
  93. #endif
  94. }
  95. }
  96. }
  97. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  98. public class TestRespondersDisposed : BeforeAfterTestAttribute {
  99. public TestRespondersDisposed () => CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
  100. public override void Before (MethodInfo methodUnderTest)
  101. {
  102. Debug.WriteLine ($"Before: {methodUnderTest.Name}");
  103. #if DEBUG_IDISPOSABLE
  104. // Clear out any lingering Responder instances from previous tests
  105. Responder.Instances.Clear ();
  106. Assert.Empty (Responder.Instances);
  107. #endif
  108. }
  109. public override void After (MethodInfo methodUnderTest)
  110. {
  111. Debug.WriteLine ($"After: {methodUnderTest.Name}");
  112. #if DEBUG_IDISPOSABLE
  113. Assert.Empty (Responder.Instances);
  114. #endif
  115. }
  116. }
  117. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  118. public class SetupFakeDriverAttribute : BeforeAfterTestAttribute {
  119. /// <summary>
  120. /// Enables test functions annotated with the [SetupFakeDriver] attribute to
  121. /// set Application.Driver to new FakeDriver(). The driver is setup with
  122. /// 10 rows and columns.
  123. /// </summary>
  124. public SetupFakeDriverAttribute () { }
  125. public override void Before (MethodInfo methodUnderTest)
  126. {
  127. Debug.WriteLine ($"Before: {methodUnderTest.Name}");
  128. Assert.Null (Application.Driver);
  129. Application.Driver = new FakeDriver () { Rows = 10, Cols = 10 };
  130. }
  131. public override void After (MethodInfo methodUnderTest)
  132. {
  133. Debug.WriteLine ($"After: {methodUnderTest.Name}");
  134. Application.Driver = null;
  135. }
  136. }
  137. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  138. public class TestDateAttribute : Xunit.Sdk.BeforeAfterTestAttribute
  139. {
  140. CultureInfo _currentCulture = CultureInfo.CurrentCulture;
  141. public TestDateAttribute()
  142. {
  143. CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
  144. }
  145. public override void Before(MethodInfo methodUnderTest)
  146. {
  147. Assert.Equal(CultureInfo.CurrentCulture, CultureInfo.InvariantCulture);
  148. }
  149. public override void After(MethodInfo methodUnderTest)
  150. {
  151. CultureInfo.CurrentCulture = _currentCulture;
  152. Assert.Equal(CultureInfo.CurrentCulture, _currentCulture);
  153. }
  154. }
  155. partial class TestHelpers {
  156. [GeneratedRegex ("\\s+$", RegexOptions.Multiline)]
  157. private static partial Regex TrailingWhiteSpaceRegEx ();
  158. [GeneratedRegex ("^\\s+", RegexOptions.Multiline)]
  159. private static partial Regex LeadingWhitespaceRegEx ();
  160. public static string DriverContentsToString (ConsoleDriver driver = null)
  161. {
  162. var sb = new StringBuilder ();
  163. driver ??= Application.Driver;
  164. var contents = driver.Contents;
  165. for (var r = 0; r < driver.Rows; r++) {
  166. for (var c = 0; c < driver.Cols; c++) {
  167. var rune = contents [r, c].Rune;
  168. if (rune.DecodeSurrogatePair (out var sp)) {
  169. sb.Append (sp);
  170. } else {
  171. sb.Append ((char)rune.Value);
  172. }
  173. if (rune.GetColumns () > 1) {
  174. c++;
  175. }
  176. // See Issue #2616
  177. //foreach (var combMark in contents [r, c].CombiningMarks) {
  178. // sb.Append ((char)combMark.Value);
  179. //}
  180. }
  181. sb.AppendLine ();
  182. }
  183. return sb.ToString ();
  184. }
  185. #pragma warning disable xUnit1013 // Public method should be marked as test
  186. /// <summary>
  187. /// Asserts that the driver contents match the expected contents, optionally ignoring any trailing whitespace.
  188. /// </summary>
  189. /// <param name="expectedLook"></param>
  190. /// <param name="output"></param>
  191. /// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
  192. /// <param name="ignoreLeadingWhitespace"></param>
  193. public static void AssertDriverContentsAre (string expectedLook, ITestOutputHelper output, ConsoleDriver driver = null, bool ignoreLeadingWhitespace = false)
  194. {
  195. #pragma warning restore xUnit1013 // Public method should be marked as test
  196. var actualLook = DriverContentsToString (driver);
  197. if (string.Equals (expectedLook, actualLook)) {
  198. return;
  199. }
  200. // get rid of trailing whitespace on each line (and leading/trailing whitespace of start/end of full string)
  201. expectedLook = TrailingWhiteSpaceRegEx ().Replace (expectedLook, "").Trim ();
  202. actualLook = TrailingWhiteSpaceRegEx ().Replace (actualLook, "").Trim ();
  203. if (ignoreLeadingWhitespace) {
  204. expectedLook = LeadingWhitespaceRegEx ().Replace (expectedLook, "").Trim ();
  205. actualLook = LeadingWhitespaceRegEx ().Replace (actualLook, "").Trim ();
  206. }
  207. // standardize line endings for the comparison
  208. expectedLook = expectedLook.Replace ("\r\n", "\n");
  209. actualLook = actualLook.Replace ("\r\n", "\n");
  210. // If test is about to fail show user what things looked like
  211. if (!string.Equals (expectedLook, actualLook)) {
  212. output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
  213. output?.WriteLine (" But Was:" + Environment.NewLine + actualLook);
  214. }
  215. Assert.Equal (expectedLook, actualLook);
  216. }
  217. /// <summary>
  218. /// Asserts that the driver contents are equal to the expected look, and that the cursor is at the expected position.
  219. /// </summary>
  220. /// <param name="expectedLook"></param>
  221. /// <param name="output"></param>
  222. /// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
  223. /// <returns></returns>
  224. public static Rect AssertDriverContentsWithFrameAre (string expectedLook, ITestOutputHelper output, ConsoleDriver driver = null)
  225. {
  226. var lines = new List<List<Rune>> ();
  227. var sb = new StringBuilder ();
  228. driver ??= Application.Driver;
  229. var x = -1;
  230. var y = -1;
  231. var w = -1;
  232. var h = -1;
  233. var contents = driver.Contents;
  234. for (var r = 0; r < driver.Rows; r++) {
  235. var runes = new List<Rune> ();
  236. for (var c = 0; c < driver.Cols; c++) {
  237. var rune = contents [r, c].Rune;
  238. if (rune != (Rune)' ') {
  239. if (x == -1) {
  240. x = c;
  241. y = r;
  242. for (var i = 0; i < c; i++) {
  243. runes.InsertRange (i, new List<Rune> { (Rune)' ' });
  244. }
  245. }
  246. if (rune.GetColumns () > 1) {
  247. c++;
  248. }
  249. if (c + 1 > w) {
  250. w = c + 1;
  251. }
  252. h = r - y + 1;
  253. }
  254. if (x > -1) {
  255. runes.Add (rune);
  256. }
  257. // See Issue #2616
  258. //foreach (var combMark in contents [r, c].CombiningMarks) {
  259. // runes.Add (combMark);
  260. //}
  261. }
  262. if (runes.Count > 0) {
  263. lines.Add (runes);
  264. }
  265. }
  266. // Remove unnecessary empty lines
  267. if (lines.Count > 0) {
  268. for (var r = lines.Count - 1; r > h - 1; r--) {
  269. lines.RemoveAt (r);
  270. }
  271. }
  272. // Remove trailing whitespace on each line
  273. foreach (var row in lines) {
  274. for (var c = row.Count - 1; c >= 0; c--) {
  275. var rune = row [c];
  276. if (rune != (Rune)' ' || row.Sum (x => x.GetColumns ()) == w) {
  277. break;
  278. }
  279. row.RemoveAt (c);
  280. }
  281. }
  282. // Convert Rune list to string
  283. for (var r = 0; r < lines.Count; r++) {
  284. var line = StringExtensions.ToString (lines [r]);
  285. if (r == lines.Count - 1) {
  286. sb.Append (line);
  287. } else {
  288. sb.AppendLine (line);
  289. }
  290. }
  291. var actualLook = sb.ToString ();
  292. if (string.Equals (expectedLook, actualLook)) {
  293. return new Rect (x > -1 ? x : 0, y > -1 ? y : 0, w > -1 ? w : 0, h > -1 ? h : 0);
  294. }
  295. // standardize line endings for the comparison
  296. expectedLook = expectedLook.Replace ("\r\n", "\n");
  297. actualLook = actualLook.Replace ("\r\n", "\n");
  298. // Remove the first and the last line ending from the expectedLook
  299. if (expectedLook.StartsWith ("\n")) {
  300. expectedLook = expectedLook [1..];
  301. }
  302. if (expectedLook.EndsWith ("\n")) {
  303. expectedLook = expectedLook [..^1];
  304. }
  305. output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
  306. output?.WriteLine (" But Was:" + Environment.NewLine + actualLook);
  307. Assert.Equal (expectedLook, actualLook);
  308. return new Rect (x > -1 ? x : 0, y > -1 ? y : 0, w > -1 ? w : 0, h > -1 ? h : 0);
  309. }
  310. #pragma warning disable xUnit1013 // Public method should be marked as test
  311. /// <summary>
  312. /// Verifies the console was rendered using the given <paramref name="expectedAttribute"/> at the given locations.
  313. /// Pass a bitmap of indexes into <paramref name="expectedAttribute"/> as <paramref name="expectedLook"/> and the
  314. /// test method will verify those colors were used in the row/col of the console during rendering
  315. /// </summary>
  316. /// <param name="expectedLook">
  317. /// Numbers between 0 and 9 for each row/col of the console. Must be valid indexes of
  318. /// <paramref name="expectedAttribute"/>
  319. /// </param>
  320. /// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
  321. /// <param name="expectedAttribute"></param>
  322. public static void AssertDriverAttributesAre (string expectedLook, ConsoleDriver driver = null, params Attribute [] expectedAttribute)
  323. {
  324. #pragma warning restore xUnit1013 // Public method should be marked as test
  325. if (expectedAttribute.Length > 10) {
  326. throw new ArgumentException ("This method only works for UIs that use at most 10 colors");
  327. }
  328. expectedLook = expectedLook.Trim ();
  329. driver ??= Application.Driver;
  330. var contents = driver.Contents;
  331. var line = 0;
  332. foreach (var lineString in expectedLook.Split ('\n').Select (l => l.Trim ())) {
  333. for (var c = 0; c < lineString.Length; c++) {
  334. var val = contents [line, c].Attribute;
  335. var match = expectedAttribute.Where (e => e == val).ToList ();
  336. switch (match.Count) {
  337. case 0:
  338. throw new Exception ($"{DriverContentsToString (driver)}\n" +
  339. $"Expected Attribute {val} at Contents[{line},{c}] {contents [line, c]}' was not found.\n" +
  340. $" Expected: {string.Join (",", expectedAttribute.Select (c => c))}\n" +
  341. $" But Was: <not found>");
  342. case > 1:
  343. throw new ArgumentException ($"Bad value for expectedColors, {match.Count} Attributes had the same Value");
  344. }
  345. var colorUsed = Array.IndexOf (expectedAttribute, match [0]).ToString () [0];
  346. var userExpected = lineString [c];
  347. if (colorUsed != userExpected) {
  348. throw new Exception ($"{DriverContentsToString (driver)}\n" +
  349. $"Unexpected Attribute at Contents[{line},{c}] {contents [line, c]}.'\n" +
  350. $" Expected: {userExpected} ({expectedAttribute [int.Parse (userExpected.ToString ())]})\n" +
  351. $" But Was: {colorUsed} ({val})\n");
  352. }
  353. }
  354. line++;
  355. }
  356. }
  357. /// <summary>
  358. /// Verifies the console used all the <paramref name="expectedColors"/> when rendering.
  359. /// If one or more of the expected colors are not used then the failure will output both
  360. /// the colors that were found to be used and which of your expectations was not met.
  361. /// </summary>
  362. /// <param name="driver">if null uses <see cref="Application.Driver"/></param>
  363. /// <param name="expectedColors"></param>
  364. internal static void AssertDriverUsedColors (ConsoleDriver driver = null, params Attribute [] expectedColors)
  365. {
  366. driver ??= Application.Driver;
  367. var contents = driver.Contents;
  368. var toFind = expectedColors.ToList ();
  369. // Contents 3rd column is an Attribute
  370. var colorsUsed = new HashSet<Attribute> ();
  371. for (var r = 0; r < driver.Rows; r++) {
  372. for (var c = 0; c < driver.Cols; c++) {
  373. var val = contents [r, c].Attribute;
  374. if (val.HasValue) {
  375. colorsUsed.Add (val.Value);
  376. var match = toFind.FirstOrDefault (e => e == val);
  377. // need to check twice because Attribute is a struct and therefore cannot be null
  378. if (toFind.Any (e => e == val)) {
  379. toFind.Remove (match);
  380. }
  381. }
  382. }
  383. }
  384. if (!toFind.Any ()) {
  385. return;
  386. }
  387. var sb = new StringBuilder ();
  388. sb.AppendLine ("The following colors were not used:" + string.Join ("; ", toFind.Select (a => a.ToString ())));
  389. sb.AppendLine ("Colors used were:" + string.Join ("; ", colorsUsed.Select (a => a.ToString ())));
  390. throw new Exception (sb.ToString ());
  391. }
  392. #pragma warning disable xUnit1013 // Public method should be marked as test
  393. /// <summary>
  394. /// Verifies two strings are equivalent. If the assert fails, output will be generated to standard
  395. /// output showing the expected and actual look.
  396. /// </summary>
  397. /// <param name="output"></param>
  398. /// <param name="expectedLook">
  399. /// A string containing the expected look. Newlines should be specified as "\r\n" as
  400. /// they will be converted to <see cref="Environment.NewLine"/> to make tests platform independent.
  401. /// </param>
  402. /// <param name="actualLook"></param>
  403. public static void AssertEqual (ITestOutputHelper output, string expectedLook, string actualLook)
  404. {
  405. // Convert newlines to platform-specific newlines
  406. expectedLook = ReplaceNewLinesToPlatformSpecific (expectedLook);
  407. // If test is about to fail show user what things looked like
  408. if (!string.Equals (expectedLook, actualLook)) {
  409. output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
  410. output?.WriteLine (" But Was:" + Environment.NewLine + actualLook);
  411. }
  412. Assert.Equal (expectedLook, actualLook);
  413. }
  414. #pragma warning restore xUnit1013 // Public method should be marked as test
  415. static string ReplaceNewLinesToPlatformSpecific (string toReplace)
  416. {
  417. var replaced = toReplace;
  418. replaced = Environment.NewLine.Length switch {
  419. 2 when !replaced.Contains ("\r\n") => replaced.Replace ("\n", Environment.NewLine),
  420. 1 => replaced.Replace ("\r\n", Environment.NewLine),
  421. var _ => replaced
  422. };
  423. return replaced;
  424. }
  425. /// <summary>
  426. /// Gets a list of instances of all classes derived from View.
  427. /// </summary>
  428. /// <returns>List of View objects</returns>
  429. public static List<View> GetAllViews () => typeof (View).Assembly.GetTypes ()
  430. .Where (type => type.IsClass && !type.IsAbstract && type.IsPublic && type.IsSubclassOf (typeof (View)))
  431. .Select (type => GetTypeInitializer (type, type.GetConstructor (Array.Empty<Type> ()))).ToList ();
  432. static View GetTypeInitializer (Type type, ConstructorInfo ctor)
  433. {
  434. View viewType = null;
  435. if (type.IsGenericType && type.IsTypeDefinition) {
  436. var gTypes = new List<Type> ();
  437. foreach (var args in type.GetGenericArguments ()) {
  438. gTypes.Add (typeof (object));
  439. }
  440. type = type.MakeGenericType (gTypes.ToArray ());
  441. Assert.IsType (type, (View)Activator.CreateInstance (type));
  442. } else {
  443. var paramsInfo = ctor.GetParameters ();
  444. Type paramType;
  445. var pTypes = new List<object> ();
  446. if (type.IsGenericType) {
  447. foreach (var args in type.GetGenericArguments ()) {
  448. paramType = args.GetType ();
  449. if (args.Name == "T") {
  450. pTypes.Add (typeof (object));
  451. } else {
  452. AddArguments (paramType, pTypes);
  453. }
  454. }
  455. }
  456. foreach (var p in paramsInfo) {
  457. paramType = p.ParameterType;
  458. if (p.HasDefaultValue) {
  459. pTypes.Add (p.DefaultValue);
  460. } else {
  461. AddArguments (paramType, pTypes);
  462. }
  463. }
  464. if (type.IsGenericType && !type.IsTypeDefinition) {
  465. viewType = (View)Activator.CreateInstance (type);
  466. Assert.IsType (type, viewType);
  467. } else {
  468. viewType = (View)ctor.Invoke (pTypes.ToArray ());
  469. Assert.IsType (type, viewType);
  470. }
  471. }
  472. return viewType;
  473. }
  474. static void AddArguments (Type paramType, List<object> pTypes)
  475. {
  476. if (paramType == typeof (Rect)) {
  477. pTypes.Add (Rect.Empty);
  478. } else if (paramType == typeof (string)) {
  479. pTypes.Add (string.Empty);
  480. } else if (paramType == typeof (int)) {
  481. pTypes.Add (0);
  482. } else if (paramType == typeof (bool)) {
  483. pTypes.Add (true);
  484. } else if (paramType.Name == "IList") {
  485. pTypes.Add (new List<object> ());
  486. } else if (paramType.Name == "View") {
  487. var top = new Toplevel ();
  488. var view = new View ();
  489. top.Add (view);
  490. pTypes.Add (view);
  491. } else if (paramType.Name == "View[]") {
  492. pTypes.Add (new View [] { });
  493. } else if (paramType.Name == "Stream") {
  494. pTypes.Add (new MemoryStream ());
  495. } else if (paramType.Name == "String") {
  496. pTypes.Add (string.Empty);
  497. } else if (paramType.Name == "TreeView`1[T]") {
  498. pTypes.Add (string.Empty);
  499. } else {
  500. pTypes.Add (null);
  501. }
  502. }
  503. }