diff --git a/01-Core/Jinget.Core/ExtensionMethods/Reflection/PropertiesExtensions.cs b/01-Core/Jinget.Core/ExtensionMethods/Reflection/PropertiesExtensions.cs index e384e94..ff69f66 100644 --- a/01-Core/Jinget.Core/ExtensionMethods/Reflection/PropertiesExtensions.cs +++ b/01-Core/Jinget.Core/ExtensionMethods/Reflection/PropertiesExtensions.cs @@ -32,7 +32,7 @@ private static IEnumerable GetDeclaredProperties(Type t) => /// /// The type to check. /// True if the type is a simple type; otherwise, false. - public static bool IsSimpleType(Type? t) + public static bool IsSimpleType(this Type? t) { while (true) { diff --git a/Tests/Jinget.Core.Tests/ExtensionMethods/Reflection/PropertiesExtensionsTests.cs b/Tests/Jinget.Core.Tests/ExtensionMethods/Reflection/PropertiesExtensionsTests.cs index 20840fb..016759c 100644 --- a/Tests/Jinget.Core.Tests/ExtensionMethods/Reflection/PropertiesExtensionsTests.cs +++ b/Tests/Jinget.Core.Tests/ExtensionMethods/Reflection/PropertiesExtensionsTests.cs @@ -10,41 +10,41 @@ struct MyStruct { public int Value; } [TestMethod] public void IsSimpleType_PrimitiveTypes_ReturnsTrue() { - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(int))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(bool))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(char))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(double))); + Assert.IsTrue(typeof(int).IsSimpleType()); + Assert.IsTrue(typeof(bool).IsSimpleType()); + Assert.IsTrue(typeof(char).IsSimpleType()); + Assert.IsTrue(typeof(double).IsSimpleType()); } [TestMethod] public void IsSimpleType_DecimalStringGuidDateTimeByteArrayEnum_ReturnsTrue() { - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(decimal))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(string))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(Guid))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(DateTime))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(byte[]))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(MyEnum))); + Assert.IsTrue(typeof(decimal).IsSimpleType()); + Assert.IsTrue(typeof(string).IsSimpleType()); + Assert.IsTrue(typeof(Guid).IsSimpleType()); + Assert.IsTrue(typeof(DateTime).IsSimpleType()); + Assert.IsTrue(typeof(byte[]).IsSimpleType()); + Assert.IsTrue(typeof(MyEnum).IsSimpleType()); } [TestMethod] public void IsSimpleType_NullableTypes_ReturnsTrue() { - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(int?))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(decimal?))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(Guid?))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(DateTime?))); - Assert.IsTrue(PropertiesExtensions.IsSimpleType(typeof(MyEnum?))); + Assert.IsTrue(typeof(int?).IsSimpleType()); + Assert.IsTrue(typeof(decimal?).IsSimpleType()); + Assert.IsTrue(typeof(Guid?).IsSimpleType()); + Assert.IsTrue(typeof(DateTime?).IsSimpleType()); + Assert.IsTrue(typeof(MyEnum?).IsSimpleType()); } [TestMethod] public void IsSimpleType_NonSimpleTypes_ReturnsFalse() { - Assert.IsFalse(PropertiesExtensions.IsSimpleType(typeof(object))); - Assert.IsFalse(PropertiesExtensions.IsSimpleType(typeof(MyClass))); - Assert.IsFalse(PropertiesExtensions.IsSimpleType(typeof(MyStruct))); - Assert.IsFalse(PropertiesExtensions.IsSimpleType(typeof(int[,]))); // multidimensional array - Assert.IsFalse(PropertiesExtensions.IsSimpleType(typeof(int[]))); // one dimensional array that is not byte[] + Assert.IsFalse(typeof(object).IsSimpleType()); + Assert.IsFalse(typeof(MyClass).IsSimpleType()); + Assert.IsFalse(typeof(MyStruct).IsSimpleType()); + Assert.IsFalse(typeof(int[,]).IsSimpleType()); // multidimensional array + Assert.IsFalse(typeof(int[]).IsSimpleType()); // one dimensional array that is not byte[] } [TestMethod] @@ -76,7 +76,7 @@ public void Should_return_all_writable_primitive_properties() var result = typeof(TestClass).GetWritableProperties(); Assert.IsNotNull(result); - Assert.IsTrue(result.Any()); + Assert.IsTrue(result.Count != 0); Assert.AreEqual(expectedResult.First(), result.First()); } } \ No newline at end of file