Skip to content

Commit

Permalink
feat(primitive-collections): including literal types for non-navigati…
Browse files Browse the repository at this point in the history
  • Loading branch information
NetanelPersikGoogle committed Nov 6, 2024
1 parent 52941fa commit 42de05f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions LogicBuilder.Expressions.Utils.Tests/TypeExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class TypeExtensionsTests
[Theory]
[InlineData(nameof(DerivedThing.Id), typeof(DerivedThing))]
[InlineData(nameof(DerivedThing.Name), typeof(BaseThing))]
[InlineData(nameof(DerivedThing.DataInBytes), typeof(BaseThing))]
[InlineData(nameof(DerivedThing.Description), typeof(DerivedThing))]
public void MemberInfoReflectedTypeMustMatchTheDeclaringType(string propertyName, Type reflectedType)
{
Expand All @@ -24,6 +25,7 @@ public void MemberInfoReflectedTypeMustMatchTheDeclaringType(string propertyName
[Theory]
[InlineData(nameof(DerivedThing.Id), typeof(DerivedThing))]
[InlineData(nameof(DerivedThing.Name), typeof(BaseThing))]
[InlineData(nameof(DerivedThing.DataInBytes), typeof(BaseThing))]
[InlineData(nameof(DerivedThing.Description), typeof(DerivedThing))]
public void MemberInfoReflectedTypeMustMatchTheDeclaringTypeForGetSelectedMembers(string propertyName,
Type reflectedType)
Expand Down Expand Up @@ -67,6 +69,17 @@ public void GetSelectedMembers_WhenSelectIsEmpty_MustReturnAllLiteralAndLiteralL
private abstract class BaseThing
{
public string Name { get; set; }
public byte[] DataInBytes { get; set; }
public string[] ParametersArray { get; set; }
public ICollection<string> Strings { get; set; }
public List<string> ParametersList { get; set; }
public List<bool> Booleans { get; set; }
public ISet<DateTime> DateTimes { get; set; }
public ISet<DateOnly> Dates { get; set; }
public HashSet<Guid> Guides { get; set; }
public uint[] UnsignedInts { get; set; }
public IEnumerable<int> Ints { get; set; }
public List<object> Objects { get; set; }
}

private class DerivedThing : BaseThing, IDerivedThing
Expand Down
13 changes: 13 additions & 0 deletions LogicBuilder.Expressions.Utils/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ private static MemberInfo[] GetValueTypeMembers(this Type parentType)
&& (info.GetMemberType().IsLiteralType() || info.GetMemberType().IsLiteralList())
).ToArray();
}

private static bool IsLiteralList(this Type type)
{
// Check if type is a List
if (!type.IsList()) return false;

// If not generic, check if it's a literal type (i.e. string[])
if (!type.IsGenericType) return type.GetElementType().IsLiteralType();

// Extract the type T from List<T> and check if it's a literal type
var firstGenericArgument = type.GetGenericArguments().First();
return firstGenericArgument.IsLiteralType();
}

private static bool IsLiteralList(this Type type)
=> type.IsList() && type.GetUnderlyingElementType().IsLiteralType();
Expand Down

0 comments on commit 42de05f

Please sign in to comment.