diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Extensions/DbCommandExtensionsTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Extensions/DbCommandExtensionsTest.cs index 62e00a6f8..6e96365cd 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Extensions/DbCommandExtensionsTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/Extensions/DbCommandExtensionsTest.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using RepoDb.Extensions; using RepoDb.Interfaces; using RepoDb.UnitTests.CustomObjects; +using System; +using System.Collections.Generic; +using System.Linq; namespace RepoDb.UnitTests.Extensions { @@ -200,5 +200,16 @@ public void TestDbCommandCreateParametersPropertyHandlerTypeLevelInvocationViaQu #endregion #endregion + + [TestMethod] + public void TestIsPlainTypeForAnoynmousType() + { + var type = (new { Property = "ABC" }).GetType(); + Assert.IsTrue(type.IsPlainType()); + Assert.IsTrue(type.IsAnonymousType()); + Assert.IsFalse(type.IsQueryObjectType()); + Assert.IsFalse(type.IsDictionaryStringObject()); + Assert.IsFalse(type.GetEnumerableClassProperties().Any()); + } } } diff --git a/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs b/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs index 417fceb06..9adb9e668 100644 --- a/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs @@ -75,7 +75,7 @@ public static bool IsNullable(this Type type) => /// /// The current type. /// Returns true if the current type is a plain class type. - public static bool IsPlainType(this Type type) => + internal static bool IsPlainType(this Type type) => (IsClassType(type) || IsAnonymousType(type)) && IsQueryObjectType(type) != true && IsDictionaryStringObject(type) != true && @@ -86,7 +86,7 @@ public static bool IsPlainType(this Type type) => /// /// The curren type. /// Returns true if the current type is of type or . - public static bool IsQueryObjectType(this Type type) => + internal static bool IsQueryObjectType(this Type type) => type == StaticType.QueryField || type == StaticType.QueryGroup; /// @@ -102,9 +102,16 @@ internal static IEnumerable AsFields(this Type type) => /// /// The current type. /// The list of the enumerable objects. - public static IEnumerable GetEnumerableClassProperties(this Type type) => - PropertyCache.Get(type).Where(classProperty => - StaticType.IEnumerable.IsAssignableFrom(classProperty.PropertyInfo.PropertyType)); + internal static IEnumerable GetEnumerableClassProperties(this Type type) => + PropertyCache.Get(type).Where(classProperty => + { + var propType = classProperty.PropertyInfo.PropertyType; + return + propType != StaticType.String && + propType != StaticType.CharArray && + propType != StaticType.ByteArray && + StaticType.IEnumerable.IsAssignableFrom(propType); + }); /// /// Converts all properties of the type into an array of objects. diff --git a/RepoDb.Core/RepoDb/RepoDb.csproj b/RepoDb.Core/RepoDb/RepoDb.csproj index 3da8b8388..d905e4957 100644 --- a/RepoDb.Core/RepoDb/RepoDb.csproj +++ b/RepoDb.Core/RepoDb/RepoDb.csproj @@ -96,5 +96,11 @@ + + + + <_Parameter1>RepoDb.UnitTests + + \ No newline at end of file