NewLife/X

负数转为Boolean时,作为true
石头 编写于 2024-09-29 00:34:11
共计: 修改2个文件,增加11行、删除1行。
修改 +1 -1
修改 +10 -0
修改 +1 -1
diff --git a/NewLife.Core/Common/Utility.cs b/NewLife.Core/Common/Utility.cs
index 1f943e0..080d509 100644
--- a/NewLife.Core/Common/Utility.cs
+++ b/NewLife.Core/Common/Utility.cs
@@ -484,7 +484,7 @@ public class DefaultConvert
             if (String.Equals(str, Boolean.TrueString, StringComparison.OrdinalIgnoreCase)) return true;
             if (String.Equals(str, Boolean.FalseString, StringComparison.OrdinalIgnoreCase)) return false;
 
-            return Int32.TryParse(str, out var n) ? n > 0 : defaultValue;
+            return Int32.TryParse(str, out var n) ? n != 0 : defaultValue;
         }
 
         try
修改 +10 -0
diff --git a/XUnitTest.Core/Reflection/ReflectTests.cs b/XUnitTest.Core/Reflection/ReflectTests.cs
index d1dbc50..415a0cd 100644
--- a/XUnitTest.Core/Reflection/ReflectTests.cs
+++ b/XUnitTest.Core/Reflection/ReflectTests.cs
@@ -264,11 +264,21 @@ public class ReflectTests
 
     [Theory]
     [InlineData("true", typeof(Boolean), true)]
+    [InlineData("False", typeof(Boolean), false)]
     [InlineData("1", typeof(Boolean), true)]
     [InlineData("0", typeof(Boolean), false)]
+    [InlineData("2", typeof(Boolean), true)]
+    [InlineData("-1", typeof(Boolean), true)]
+    [InlineData(1, typeof(Boolean), true)]
+    [InlineData(0, typeof(Boolean), false)]
+    [InlineData(-1, typeof(Boolean), true)]
     [InlineData("1234", typeof(Int16), (Int16)1234)]
     [InlineData("1234", typeof(Int32), 1234)]
+    [InlineData("-1234", typeof(Int32), -1234)]
+    [InlineData("0", typeof(Int32), 0)]
+    [InlineData("-1", typeof(Int32), -1)]
     [InlineData("12.34", typeof(Double), 12.34)]
+    [InlineData("-12.34", typeof(Double), -12.34)]
     [InlineData("byte[]", typeof(Type), typeof(Byte[]))]
     public void ChangeTypeTest(Object value, Type targetType, Object target)
     {