TestRectangleConverter.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. //
  2. // Tests for System.Drawing.RectangleConverter.cs
  3. //
  4. // Author:
  5. // Ravindra ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.ComponentModel;
  32. using System.ComponentModel.Design.Serialization;
  33. using System.Drawing;
  34. using System.Globalization;
  35. using System.Threading;
  36. using NUnit.Framework;
  37. namespace MonoTests.System.Drawing
  38. {
  39. [TestFixture]
  40. public class RectangleConverterTest
  41. {
  42. Rectangle rect;
  43. Rectangle rectneg;
  44. RectangleConverter rconv;
  45. String rectStrInvariant;
  46. String rectnegStrInvariant;
  47. [SetUp]
  48. public void SetUp ()
  49. {
  50. rect = new Rectangle (10, 10, 20, 30);
  51. rectStrInvariant = rect.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
  52. rect.Y + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
  53. rect.Width + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
  54. rect.Height;
  55. rectneg = new Rectangle (-10, -10, 20, 30);
  56. rectnegStrInvariant = rectneg.X + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " "
  57. + rectneg.Y + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " +
  58. rectneg.Width + CultureInfo.InvariantCulture.TextInfo.ListSeparator + " " + rectneg.Height;
  59. rconv = (RectangleConverter) TypeDescriptor.GetConverter (rect);
  60. }
  61. [Test]
  62. public void TestCanConvertFrom ()
  63. {
  64. Assert.IsTrue (rconv.CanConvertFrom (typeof (String)), "CCF#1");
  65. Assert.IsTrue (rconv.CanConvertFrom (null, typeof (String)), "CCF#2");
  66. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Rectangle)), "CCF#3");
  67. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (RectangleF)), "CCF#4");
  68. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Point)), "CCF#5");
  69. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (PointF)), "CCF#6");
  70. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Size)), "CCF#7");
  71. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (SizeF)), "CCF#8");
  72. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (Object)), "CCF#9");
  73. Assert.IsFalse (rconv.CanConvertFrom (null, typeof (int)), "CCF#10");
  74. Assert.IsTrue (rconv.CanConvertFrom (null, typeof (InstanceDescriptor)), "CCF#11");
  75. }
  76. [Test]
  77. public void TestCanConvertTo ()
  78. {
  79. Assert.IsTrue (rconv.CanConvertTo (typeof (String)), "CCT#1");
  80. Assert.IsTrue (rconv.CanConvertTo (null, typeof (String)), "CCT#2");
  81. Assert.IsFalse (rconv.CanConvertTo (null, typeof (Rectangle)), "CCT#3");
  82. Assert.IsFalse (rconv.CanConvertTo (null, typeof (RectangleF)), "CCT#4");
  83. Assert.IsFalse (rconv.CanConvertTo (null, typeof (Point)), "CCT#5");
  84. Assert.IsFalse (rconv.CanConvertTo (null, typeof (PointF)), "CCT#6");
  85. Assert.IsFalse (rconv.CanConvertTo (null, typeof (Size)), "CCT#7");
  86. Assert.IsFalse (rconv.CanConvertTo (null, typeof (SizeF)), "CCT#8");
  87. Assert.IsFalse (rconv.CanConvertTo (null, typeof (Object)), "CCT#9");
  88. Assert.IsFalse (rconv.CanConvertTo (null, typeof (int)), "CCT#10");
  89. }
  90. [Test]
  91. public void TestConvertFrom ()
  92. {
  93. Assert.AreEqual (rect, (Rectangle) rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  94. "10, 10, 20, 30"), "CF#1");
  95. Assert.AreEqual (rectneg, (Rectangle) rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  96. "-10, -10, 20, 30"), "CF#2");
  97. try {
  98. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  99. "10, 10");
  100. Assert.Fail ("CF#3: must throw ArgumentException");
  101. } catch (Exception e) {
  102. Assert.IsTrue (e is ArgumentException, "CF#3");
  103. }
  104. try {
  105. rconv.ConvertFrom ("10");
  106. Assert.Fail ("CF#3a: must throw ArgumentException");
  107. } catch (Exception e) {
  108. Assert.IsTrue (e is ArgumentException, "CF#3a");
  109. }
  110. try {
  111. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  112. "1, 1, 1, 1, 1");
  113. Assert.Fail ("CF#4: must throw ArgumentException");
  114. } catch (Exception e) {
  115. Assert.IsTrue (e is ArgumentException, "CF#4");
  116. }
  117. try {
  118. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  119. "*1, 1, 1, 1");
  120. Assert.Fail ("CF#5: must throw Exception");
  121. } catch (Exception ex) {
  122. Assert.AreEqual (typeof (Exception), ex.GetType (), "CF#5-2");
  123. Assert.IsNotNull (ex.InnerException, "CF#5-3");
  124. Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "CF#5-4");
  125. }
  126. try {
  127. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  128. new Rectangle (10, 10, 100, 100));
  129. Assert.Fail ("CF#6: must throw NotSupportedException");
  130. } catch (Exception e) {
  131. Assert.IsTrue (e is NotSupportedException, "CF#6");
  132. }
  133. try {
  134. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  135. new RectangleF (10, 10, 100, 100));
  136. Assert.Fail ("CF#7: must throw NotSupportedException");
  137. } catch (Exception e) {
  138. Assert.IsTrue (e is NotSupportedException, "CF#7");
  139. }
  140. try {
  141. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  142. new Point (10, 10));
  143. Assert.Fail ("CF#8: must throw NotSupportedException");
  144. } catch (Exception e) {
  145. Assert.IsTrue (e is NotSupportedException, "CF#8");
  146. }
  147. try {
  148. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  149. new PointF (10, 10));
  150. Assert.Fail ("CF#9: must throw NotSupportedException");
  151. } catch (Exception e) {
  152. Assert.IsTrue (e is NotSupportedException, "CF#9");
  153. }
  154. try {
  155. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  156. new Size (10, 10));
  157. Assert.Fail ("CF#10: must throw NotSupportedException");
  158. } catch (Exception e) {
  159. Assert.IsTrue (e is NotSupportedException, "CF#10");
  160. }
  161. try {
  162. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  163. new SizeF (10, 10));
  164. Assert.Fail ("CF#11: must throw NotSupportedException");
  165. } catch (Exception e) {
  166. Assert.IsTrue (e is NotSupportedException, "CF#11");
  167. }
  168. try {
  169. rconv.ConvertFrom (null, CultureInfo.InvariantCulture,
  170. new Object ());
  171. Assert.Fail ("CF#12: must throw NotSupportedException");
  172. } catch (Exception e) {
  173. Assert.IsTrue (e is NotSupportedException, "CF#12");
  174. }
  175. try {
  176. rconv.ConvertFrom (null, CultureInfo.InvariantCulture, 1001);
  177. Assert.Fail ("CF#13: must throw NotSupportedException");
  178. } catch (Exception e) {
  179. Assert.IsTrue (e is NotSupportedException, "CF#13");
  180. }
  181. }
  182. [Test]
  183. public void TestConvertTo ()
  184. {
  185. Assert.AreEqual (rectStrInvariant, (String) rconv.ConvertTo (null,
  186. CultureInfo.InvariantCulture, rect, typeof (String)), "CT#1");
  187. Assert.AreEqual (rectnegStrInvariant, (String) rconv.ConvertTo (null,
  188. CultureInfo.InvariantCulture, rectneg, typeof (String)), "CT#2");
  189. try {
  190. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  191. rect, typeof (Rectangle));
  192. Assert.Fail ("CT#3: must throw NotSupportedException");
  193. } catch (Exception e) {
  194. Assert.IsTrue (e is NotSupportedException, "CT#3");
  195. }
  196. try {
  197. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  198. rect, typeof (RectangleF));
  199. Assert.Fail ("CT#4: must throw NotSupportedException");
  200. } catch (Exception e) {
  201. Assert.IsTrue (e is NotSupportedException, "CT#4");
  202. }
  203. try {
  204. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  205. rect, typeof (Size));
  206. Assert.Fail ("CT#5: must throw NotSupportedException");
  207. } catch (Exception e) {
  208. Assert.IsTrue (e is NotSupportedException, "CT#5");
  209. }
  210. try {
  211. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  212. rect, typeof (SizeF));
  213. Assert.Fail ("CT#6: must throw NotSupportedException");
  214. } catch (Exception e) {
  215. Assert.IsTrue (e is NotSupportedException, "CT#6");
  216. }
  217. try {
  218. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  219. rect, typeof (Point));
  220. Assert.Fail ("CT#7: must throw NotSupportedException");
  221. } catch (Exception e) {
  222. Assert.IsTrue (e is NotSupportedException, "CT#7");
  223. }
  224. try {
  225. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  226. rect, typeof (PointF));
  227. Assert.Fail ("CT#8: must throw NotSupportedException");
  228. } catch (Exception e) {
  229. Assert.IsTrue (e is NotSupportedException, "CT#8");
  230. }
  231. try {
  232. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  233. rect, typeof (Object));
  234. Assert.Fail ("CT#9: must throw NotSupportedException");
  235. } catch (Exception e) {
  236. Assert.IsTrue (e is NotSupportedException, "CT#9");
  237. }
  238. try {
  239. rconv.ConvertTo (null, CultureInfo.InvariantCulture,
  240. rect, typeof (int));
  241. Assert.Fail ("CT#10: must throw NotSupportedException");
  242. } catch (Exception e) {
  243. Assert.IsTrue (e is NotSupportedException, "CT#10");
  244. }
  245. }
  246. [Test]
  247. public void TestGetCreateInstanceSupported ()
  248. {
  249. Assert.IsTrue (rconv.GetCreateInstanceSupported (), "GCIS#1");
  250. Assert.IsTrue (rconv.GetCreateInstanceSupported (null), "GCIS#2");
  251. }
  252. [Test]
  253. public void TestCreateInstance ()
  254. {
  255. Rectangle rectInstance;
  256. Hashtable ht = new Hashtable ();
  257. ht.Add ("X", 10); ht.Add ("Y", 10);
  258. ht.Add ("Width", 20); ht.Add ("Height", 30);
  259. rectInstance = (Rectangle) rconv.CreateInstance (ht);
  260. Assert.AreEqual (rect, rectInstance, "CI#1");
  261. ht.Clear ();
  262. ht.Add ("X", -10); ht.Add ("Y", -10);
  263. ht.Add ("Width", 20); ht.Add ("Height", 30);
  264. rectInstance = (Rectangle) rconv.CreateInstance (null, ht);
  265. Assert.AreEqual (rectneg, rectInstance, "CI#2");
  266. // Property names are case-sensitive. It should throw
  267. // NullRefExc if any of the property names does not match
  268. ht.Clear ();
  269. ht.Add ("x", -10); ht.Add ("Y", -10);
  270. ht.Add ("Width", 20); ht.Add ("Height", 30);
  271. try {
  272. rectInstance = (Rectangle) rconv.CreateInstance (null, ht);
  273. Assert.Fail ("CI#3: must throw NullReferenceException");
  274. } catch (Exception e) {
  275. Assert.IsTrue (e is NullReferenceException, "CI#3");
  276. }
  277. }
  278. [Test]
  279. public void TestGetPropertiesSupported ()
  280. {
  281. Assert.IsTrue (rconv.GetPropertiesSupported (), "GPS#1");
  282. Assert.IsTrue (rconv.GetPropertiesSupported (null), "GPS#2");
  283. }
  284. [Test]
  285. [Ignore ("This test fails because of bug #58435")]
  286. public void TestGetProperties ()
  287. {
  288. Attribute [] attrs;
  289. PropertyDescriptorCollection propsColl;
  290. propsColl = rconv.GetProperties (rect);
  291. Assert.AreEqual (4, propsColl.Count, "GP1#1");
  292. Assert.AreEqual (rect.X, propsColl["X"].GetValue (rect), "GP1#2");
  293. Assert.AreEqual (rect.Y, propsColl["Y"].GetValue (rect), "GP1#3");
  294. Assert.AreEqual (rect.Width, propsColl["Width"].GetValue (rect), "GP1#4");
  295. Assert.AreEqual (rect.Height, propsColl["Height"].GetValue (rect), "GP1#5");
  296. propsColl = rconv.GetProperties (null, rectneg);
  297. Assert.AreEqual (4, propsColl.Count, "GP2#1");
  298. Assert.AreEqual (rectneg.X, propsColl["X"].GetValue (rectneg), "GP2#2");
  299. Assert.AreEqual (rectneg.Y, propsColl["Y"].GetValue (rectneg), "GP2#3");
  300. Assert.AreEqual (rectneg.Width, propsColl["Width"].GetValue (rectneg), "GP2#4");
  301. Assert.AreEqual (rectneg.Height, propsColl["Height"].GetValue (rectneg), "GP2#5");
  302. propsColl = rconv.GetProperties (null, rect, null);
  303. Assert.AreEqual (11, propsColl.Count, "GP3#1");
  304. Assert.AreEqual (rect.X, propsColl["X"].GetValue (rect), "GP3#2");
  305. Assert.AreEqual (rect.Y, propsColl["Y"].GetValue (rect), "GP3#3");
  306. Assert.AreEqual (rect.Width, propsColl["Width"].GetValue (rect), "GP3#4");
  307. Assert.AreEqual (rect.Height, propsColl["Height"].GetValue (rect), "GP3#5");
  308. Assert.AreEqual (rect.Top, propsColl["Top"].GetValue (rect), "GP3#6");
  309. Assert.AreEqual (rect.Bottom, propsColl["Bottom"].GetValue (rect), "GP3#7");
  310. Assert.AreEqual (rect.Left, propsColl["Left"].GetValue (rect), "GP3#8");
  311. Assert.AreEqual (rect.Right, propsColl["Right"].GetValue (rect), "GP3#9");
  312. Assert.AreEqual (rect.Location, propsColl["Location"].GetValue (rect), "GP3#10");
  313. Assert.AreEqual (rect.Size, propsColl["Size"].GetValue (rect), "GP3#11");
  314. Assert.AreEqual (rect.IsEmpty, propsColl["IsEmpty"].GetValue (rect), "GP3#12");
  315. Type type = typeof (Rectangle);
  316. attrs = Attribute.GetCustomAttributes (type, true);
  317. propsColl = rconv.GetProperties (null, rect, attrs);
  318. Assert.AreEqual (0, propsColl.Count, "GP3#13");
  319. }
  320. [Test]
  321. public void ConvertFromInvariantString_string ()
  322. {
  323. Assert.AreEqual (rect, rconv.ConvertFromInvariantString (rectStrInvariant),
  324. "CFISS#1");
  325. Assert.AreEqual (rectneg, rconv.ConvertFromInvariantString (rectnegStrInvariant),
  326. "CFISS#2");
  327. }
  328. [Test]
  329. [ExpectedException (typeof (ArgumentException))]
  330. public void ConvertFromInvariantString_string_exc_1 ()
  331. {
  332. rconv.ConvertFromInvariantString ("1, 2, 3");
  333. }
  334. [Test]
  335. public void ConvertFromInvariantString_string_exc_2 ()
  336. {
  337. try {
  338. rconv.ConvertFromInvariantString ("hello");
  339. Assert.Fail ("#1");
  340. } catch (Exception ex) {
  341. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  342. Assert.IsNotNull (ex.InnerException, "#3");
  343. Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
  344. }
  345. }
  346. [Test]
  347. public void ConvertFromString_string ()
  348. {
  349. // save current culture
  350. CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
  351. try {
  352. PerformConvertFromStringTest (new CultureInfo ("en-US"));
  353. PerformConvertFromStringTest (new CultureInfo ("nl-BE"));
  354. PerformConvertFromStringTest (new MyCultureInfo ());
  355. } finally {
  356. // restore original culture
  357. Thread.CurrentThread.CurrentCulture = currentCulture;
  358. }
  359. }
  360. [Test]
  361. [ExpectedException (typeof (ArgumentException))]
  362. public void ConvertFromString_string_exc_1 ()
  363. {
  364. CultureInfo culture = CultureInfo.CurrentCulture;
  365. rconv.ConvertFromString (string.Format(culture,
  366. "1{0} 2{0} 3{0} 4{0} 5", culture.TextInfo.ListSeparator));
  367. }
  368. [Test]
  369. public void ConvertFromString_string_exc_2 ()
  370. {
  371. try {
  372. rconv.ConvertFromString ("hello");
  373. Assert.Fail ("#1");
  374. } catch (Exception ex) {
  375. Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
  376. Assert.IsNotNull (ex.InnerException, "#3");
  377. Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
  378. }
  379. }
  380. [Test]
  381. public void ConvertToInvariantString_string ()
  382. {
  383. Assert.AreEqual (rectStrInvariant, rconv.ConvertToInvariantString (rect),
  384. "CFISS#1");
  385. Assert.AreEqual (rectnegStrInvariant, rconv.ConvertToInvariantString (rectneg),
  386. "CFISS#2");
  387. }
  388. [Test]
  389. public void ConvertToString_string () {
  390. // save current culture
  391. CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
  392. try {
  393. PerformConvertToStringTest (new CultureInfo ("en-US"));
  394. PerformConvertToStringTest (new CultureInfo ("nl-BE"));
  395. PerformConvertToStringTest (new MyCultureInfo ());
  396. } finally {
  397. // restore original culture
  398. Thread.CurrentThread.CurrentCulture = currentCulture;
  399. }
  400. }
  401. [Test]
  402. public void GetStandardValuesSupported ()
  403. {
  404. Assert.IsFalse (rconv.GetStandardValuesSupported ());
  405. }
  406. [Test]
  407. public void GetStandardValues ()
  408. {
  409. Assert.IsNull (rconv.GetStandardValues ());
  410. }
  411. [Test]
  412. public void GetStandardValuesExclusive ()
  413. {
  414. Assert.IsFalse (rconv.GetStandardValuesExclusive ());
  415. }
  416. private void PerformConvertFromStringTest (CultureInfo culture)
  417. {
  418. // set current culture
  419. Thread.CurrentThread.CurrentCulture = culture;
  420. // perform tests
  421. Assert.AreEqual (rect, rconv.ConvertFromString (CreateRectangleString (rect)),
  422. "CFSS#1-" + culture.Name);
  423. Assert.AreEqual (rectneg, rconv.ConvertFromString (CreateRectangleString (rectneg)),
  424. "CFSS#2-" + culture.Name);
  425. }
  426. private void PerformConvertToStringTest (CultureInfo culture)
  427. {
  428. // set current culture
  429. Thread.CurrentThread.CurrentCulture = culture;
  430. // perform tests
  431. Assert.AreEqual (CreateRectangleString (rect), rconv.ConvertToString (rect),
  432. "CFISS#1-" + culture.Name);
  433. Assert.AreEqual (CreateRectangleString (rectneg), rconv.ConvertToString (rectneg),
  434. "CFISS#2-" + culture.Name);
  435. }
  436. private static string CreateRectangleString (Rectangle rectangle)
  437. {
  438. return CreateRectangleString (CultureInfo.CurrentCulture, rectangle);
  439. }
  440. private static string CreateRectangleString (CultureInfo culture, Rectangle rectangle)
  441. {
  442. return string.Format ("{0}{1} {2}{1} {3}{1} {4}", rectangle.X.ToString (culture),
  443. culture.TextInfo.ListSeparator, rectangle.Y.ToString (culture),
  444. rectangle.Width.ToString (culture), rectangle.Height.ToString (culture));
  445. }
  446. [Serializable]
  447. private sealed class MyCultureInfo : CultureInfo
  448. {
  449. internal MyCultureInfo ()
  450. : base ("en-US")
  451. {
  452. }
  453. public override object GetFormat (Type formatType)
  454. {
  455. if (formatType == typeof (NumberFormatInfo)) {
  456. NumberFormatInfo nfi = (NumberFormatInfo) ((NumberFormatInfo) base.GetFormat (formatType)).Clone ();
  457. nfi.NegativeSign = "myNegativeSign";
  458. return NumberFormatInfo.ReadOnly (nfi);
  459. } else {
  460. return base.GetFormat (formatType);
  461. }
  462. }
  463. }
  464. }
  465. }