Skip to content

Commit 40a9f7d

Browse files
committed
added isnumber
1 parent 3ee0c49 commit 40a9f7d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Extensions/ObjectExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace Extensions
2+
{
3+
public static class ObjectExtensions
4+
{
5+
public static bool IsNumber(this object value)
6+
{
7+
return value is sbyte
8+
|| value is byte
9+
|| value is short
10+
|| value is ushort
11+
|| value is int
12+
|| value is uint
13+
|| value is long
14+
|| value is ulong
15+
|| value is float
16+
|| value is double
17+
|| value is decimal;
18+
}
19+
}
20+
}

tests/Extensions.Tests/DateTimeExtensionsTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,20 @@ public void ShouldCalculateAgeOnSpecificDate()
3030
birthday.ToAgeAtDate(new DateTime(2022, 4, 12)).Should().Be(31);
3131
}
3232
}
33+
34+
public class ObjectExtensionsTests
35+
{
36+
[Theory]
37+
[InlineData(false, false)]
38+
[InlineData(null, false)]
39+
[InlineData("lallallero", false)]
40+
[InlineData(123, true)]
41+
[InlineData(1.3, true)]
42+
[InlineData(-123, true)]
43+
[InlineData(-1.3, true)]
44+
public void ShouldCheckIfNumber(object o, bool expected)
45+
{
46+
o.IsNumber().Should().Be(expected);
47+
}
48+
}
3349
}

0 commit comments

Comments
 (0)