From 998e3dd16ccc6b8a4a079495c5b2b8e73e43e4d3 Mon Sep 17 00:00:00 2001 From: Scalpel_cp <165da7fc5536ee16440a98f161bfa866a8b94595G55xazV5> Date: Sat, 6 Sep 2008 09:27:34 +0000 Subject: [PATCH] Plugged Boolean.Parse(string) and Boolean.TryParse(string, out bool) Added methodname displaying in build GUI again --- source/FrodeTest/Program.cs | 4 +- source/FrodeTest/Test/BoolTest.cs | 46 ++++++++++++++++- .../System/BooleanImpl.cs | 50 ++++++++++++++++--- source/Indy.IL2CPU/Engine.cs | 2 +- 4 files changed, 91 insertions(+), 11 deletions(-) diff --git a/source/FrodeTest/Program.cs b/source/FrodeTest/Program.cs index b4915caa9..1e6ed57e8 100644 --- a/source/FrodeTest/Program.cs +++ b/source/FrodeTest/Program.cs @@ -27,7 +27,7 @@ namespace FrodeTest { //while (true) //Console.Beep(2000, 2); - Console.Beep(); + //Console.Beep(); //Cosmos.Hardware.PIT.PlaySound(3000); //Console.Beep(); //Shell.Session.Run(); @@ -54,7 +54,7 @@ namespace FrodeTest //Test.BasicTest.RunTest(); //Test.SwitchTest.RunTest(); //Console.ReadLine(); - //Test.BoolTest.RunTest(); + Test.BoolTest.RunTest(); //Test.InterfaceTest.RunTest(); //Test.ExtensionMethodsTest.RunTest(); //Test.BinaryHelperTest.RunTest(); diff --git a/source/FrodeTest/Test/BoolTest.cs b/source/FrodeTest/Test/BoolTest.cs index e16cda3a5..829b158c0 100644 --- a/source/FrodeTest/Test/BoolTest.cs +++ b/source/FrodeTest/Test/BoolTest.cs @@ -14,8 +14,52 @@ namespace FrodeTest.Test Console.WriteLine("true.ToString() gives: " + yes.ToString()); Console.WriteLine("false.ToString() gives: " + no.ToString()); - + //Testing returntype CompareNullReturnFalse(); + + //Testing parsing + Check.Text = "Bool Parse"; + if (Boolean.Parse("True")) + Check.OK(); + else + Check.Fail(); + + //if (Boolean.Parse("tRUE")) //Doesn't work because of .Equals(string, StringComparison) + // Check.OK(); + //else + // Check.Fail(); + + if (Boolean.Parse("False")) + Check.Fail(); + else + Check.OK(); + + try + { + Check.Text = "ArgumentNull check"; + Boolean.Parse(null); + Check.Fail(); + } + catch (ArgumentNullException) + { + Check.OK(); + } + catch (Exception ex) + { + Check.Fail(); + } + + Check.Text = "TryParse"; + bool result = false; + Boolean.TryParse("True", out result); + if (result) + Check.OK(); + else + Check.Fail(); + + Check.Text = "TryParseShouldGiveFalse"; + if (!Boolean.TryParse("blabla", out result)) + Check.OK(); } public static bool CompareNullReturnFalse() diff --git a/source/Indy.IL2CPU.IL/CustomImplementations/System/BooleanImpl.cs b/source/Indy.IL2CPU.IL/CustomImplementations/System/BooleanImpl.cs index 2e5628ff7..47a45b867 100644 --- a/source/Indy.IL2CPU.IL/CustomImplementations/System/BooleanImpl.cs +++ b/source/Indy.IL2CPU.IL/CustomImplementations/System/BooleanImpl.cs @@ -7,13 +7,49 @@ using Indy.IL2CPU.Plugs; namespace Indy.IL2CPU.IL.CustomImplementations.System { [Plug(Target=typeof(bool))] public static class BooleanImpl { - public static string ToString(ref bool aThis) { - if (aThis) { - return "true"; - } else { - return "false"; - } - } + //NOTE; Not used any more?? + //public static string ToString(ref Boolean aThis) + //{ + // if (aThis) + // { + // return "true"; + // } + // else + // { + // return "false"; + // } + //} + public static bool Parse(string aBoolText) + { + if (aBoolText == null) + throw new ArgumentNullException("aBoolText"); + + Boolean xResult = false; + if (!Boolean.TryParse(aBoolText, out xResult)) + { + throw new FormatException("String was not recognized as a valid Boolean."); + } + return xResult; + } + + public static bool TryParse(string aBoolText, out Boolean aResult) + { + aResult = false; + + //Currently .Equals(string, StringComparison) does not work, so only exactly "True" and "False" work. Not "true", "tRuE" etc. + if ("True".Equals(aBoolText, StringComparison.OrdinalIgnoreCase)) + { + aResult = true; + return true; + } + else if ("False".Equals(aBoolText, StringComparison.OrdinalIgnoreCase)) + { + aResult = false; + return true; + } + + return false; + } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs index d1fd80be0..977a9b3a4 100644 --- a/source/Indy.IL2CPU/Engine.cs +++ b/source/Indy.IL2CPU/Engine.cs @@ -174,7 +174,7 @@ namespace Indy.IL2CPU { return mProgressMessage; } set { - //mProgressMessage = value; + mProgressMessage = value; OnProgressChanged(); } }