Skip to content

Commit

Permalink
Merge pull request #657 from fredliex/Fix/IsPlainType_for_string
Browse files Browse the repository at this point in the history
fix #650 TypeExtension.IsPlainType seems to misjudge the string property
  • Loading branch information
mikependon authored Dec 2, 2020
2 parents 505302f + 8f5b5e6 commit 0be471d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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());
}
}
}
17 changes: 12 additions & 5 deletions RepoDb.Core/RepoDb/Extensions/TypeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static bool IsNullable(this Type type) =>
/// </summary>
/// <param name="type">The current type.</param>
/// <returns>Returns true if the current type is a plain class type.</returns>
public static bool IsPlainType(this Type type) =>
internal static bool IsPlainType(this Type type) =>
(IsClassType(type) || IsAnonymousType(type)) &&
IsQueryObjectType(type) != true &&
IsDictionaryStringObject(type) != true &&
Expand All @@ -86,7 +86,7 @@ public static bool IsPlainType(this Type type) =>
/// </summary>
/// <param name="type">The curren type.</param>
/// <returns>Returns true if the current type is of type <see cref="QueryField"/> or <see cref="QueryGroup"/>.</returns>
public static bool IsQueryObjectType(this Type type) =>
internal static bool IsQueryObjectType(this Type type) =>
type == StaticType.QueryField || type == StaticType.QueryGroup;

/// <summary>
Expand All @@ -102,9 +102,16 @@ internal static IEnumerable<Field> AsFields(this Type type) =>
/// </summary>
/// <param name="type">The current type.</param>
/// <returns>The list of the enumerable <see cref="ClassProperty"/> objects.</returns>
public static IEnumerable<ClassProperty> GetEnumerableClassProperties(this Type type) =>
PropertyCache.Get(type).Where(classProperty =>
StaticType.IEnumerable.IsAssignableFrom(classProperty.PropertyInfo.PropertyType));
internal static IEnumerable<ClassProperty> 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);
});

/// <summary>
/// Converts all properties of the type into an array of <see cref="ClassProperty"/> objects.
Expand Down
6 changes: 6 additions & 0 deletions RepoDb.Core/RepoDb/RepoDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,11 @@
</None>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>RepoDb.UnitTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>

0 comments on commit 0be471d

Please sign in to comment.