Skip to content

Commit

Permalink
PR fixes, updated test, added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
moxplod committed Aug 31, 2024
1 parent f43e8ec commit 322550b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
4 changes: 4 additions & 0 deletions docs/pages/guide/gridifyMapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ This method clears the list of mappings

This method returns list of current mappings.

## GetCurrentMapsByType

This method returns list of current mappings for the given type.

## GridifyMapperConfiguration

``` csharp
Expand Down
35 changes: 22 additions & 13 deletions src/Gridify/GridifyMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,34 @@ public IEnumerable<IGMap<T>> GetCurrentMapsByType(HashSet<Type> targetTypes)
{
foreach (var map in _mappings)
{
if (map.To.Body is UnaryExpression unaryExpression)
switch (map.To.Body)
{
if (targetTypes.Contains(unaryExpression.Operand.Type))
case UnaryExpression unaryExpression:
{
yield return map;
if (targetTypes.Contains(unaryExpression.Operand.Type))
{
yield return map;
}

break;
}
}
else if (map.To.Body is MethodCallExpression methodCallExpression)
{
if (targetTypes.Contains(methodCallExpression.Type))
case MethodCallExpression methodCallExpression:
{
yield return map;
if (targetTypes.Contains(methodCallExpression.Type))
{
yield return map;
}

break;
}
}
else if (map.To.Body is MemberExpression memberExpression)
{
if (targetTypes.Contains(memberExpression.Type))
case MemberExpression memberExpression:
{
yield return map;
if (targetTypes.Contains(memberExpression.Type))
{
yield return map;
}

break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Gridify.Tests/GridifyMapperShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void AddMap_DuplicateKey_ShouldThrowErrorIfOverrideIfExistsIsFalse()
}

[Theory]
[InlineData(typeof(DateTime), 0)]
[InlineData(typeof(DateTime), 1)]
[InlineData(typeof(DateTime?), 1)]
[InlineData(typeof(Guid), 1)]
[InlineData(typeof(string), 2)]
Expand Down
1 change: 1 addition & 0 deletions test/Gridify.Tests/TestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public TestClass(int id, string name, TestClass? classProp, Guid myGuid = defaul
public string? Name { get; set; } = string.Empty;
public TestClass? ChildClass { get; set; }
public DateTime? MyDateTime { get; set; }
public DateTime AnotherDateTime { get; set; }
public Guid MyGuid { get; set; }
public string? Tag { get; set; }

Expand Down

0 comments on commit 322550b

Please sign in to comment.