Skip to content

Commit

Permalink
added isnumber
Browse files Browse the repository at this point in the history
  • Loading branch information
ildoc committed Oct 3, 2022
1 parent 3ee0c49 commit 40a9f7d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Extensions
{
public static class ObjectExtensions
{
public static bool IsNumber(this object value)
{
return value is sbyte
|| value is byte
|| value is short
|| value is ushort
|| value is int
|| value is uint
|| value is long
|| value is ulong
|| value is float
|| value is double
|| value is decimal;
}
}
}
16 changes: 16 additions & 0 deletions tests/Extensions.Tests/DateTimeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ public void ShouldCalculateAgeOnSpecificDate()
birthday.ToAgeAtDate(new DateTime(2022, 4, 12)).Should().Be(31);
}
}

public class ObjectExtensionsTests
{
[Theory]
[InlineData(false, false)]
[InlineData(null, false)]
[InlineData("lallallero", false)]
[InlineData(123, true)]
[InlineData(1.3, true)]
[InlineData(-123, true)]
[InlineData(-1.3, true)]
public void ShouldCheckIfNumber(object o, bool expected)
{
o.IsNumber().Should().Be(expected);
}
}
}

0 comments on commit 40a9f7d

Please sign in to comment.