Skip to content

Commit 1fa3e15

Browse files
authored
Fix AbstractDynamicLinqCustomTypeProvider.ResolveTypeBySimpleName to use AdditionalTypes (#896)
1 parent 66fd487 commit 1fa3e15

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

src/System.Linq.Dynamic.Core/CustomTypeProviders/AbstractDynamicLinqCustomTypeProvider.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,11 @@ protected Type[] FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumerable<Assembl
6666
Check.NotNull(assemblies);
6767
Check.NotEmpty(simpleTypeName);
6868

69-
var types = FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies);
69+
var types = FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies).Union(AdditionalTypes);
7070
var fullNames = types.Select(t => t.FullName!).Distinct().ToArray();
7171
var firstMatchingFullname = fullNames.FirstOrDefault(fn => fn.EndsWith($".{simpleTypeName}"));
7272

73-
if (firstMatchingFullname == null)
74-
{
75-
return null;
76-
}
77-
78-
return types.FirstOrDefault(t => t.FullName == firstMatchingFullname);
73+
return firstMatchingFullname == null ? null : types.FirstOrDefault(t => t.FullName == firstMatchingFullname);
7974
}
8075

8176
#if (UAP10_0 || NETSTANDARD)

test/System.Linq.Dynamic.Core.Tests/CustomTypeProviders/DefaultDynamicLinqCustomTypeProviderTests.cs

+31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using System.Linq.Dynamic.Core.CustomTypeProviders;
4+
using System.Linq.Dynamic.Core.Tests.TestClasses;
45
using FluentAssertions;
56
using NFluent;
67
using Xunit;
@@ -61,4 +62,34 @@ public void DefaultDynamicLinqCustomTypeProvider_ResolveType_DefinedReturnsType(
6162
// Assert
6263
Check.That(result).IsNotNull();
6364
}
65+
66+
[Fact]
67+
public void DefaultDynamicLinqCustomTypeProvider_ResolveTypeBySimpleName_UsesAdditionalTypes()
68+
{
69+
// Act
70+
var result = _sut.ResolveTypeBySimpleName(nameof(TestClassWithDynamicLinqAttribute));
71+
72+
// Assert
73+
Check.That(result).IsNotNull();
74+
}
75+
76+
[Fact]
77+
public void DefaultDynamicLinqCustomTypeProvider_ResolveTypeBySimpleName_UsesTypesMarkedWithDynamicLinqTypeAttribute()
78+
{
79+
// Act
80+
var result = _sut.ResolveTypeBySimpleName(nameof(DirectoryInfo));
81+
82+
// Assert
83+
Check.That(result).IsNotNull();
84+
}
85+
86+
[Fact]
87+
public void DefaultDynamicLinqCustomTypeProvider_ResolveTypeBySimpleName_UnknownReturnsNull()
88+
{
89+
// Act
90+
var result = _sut.ResolveTypeBySimpleName("Dummy123");
91+
92+
// Assert
93+
Check.That(result).IsNull();
94+
}
6495
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Linq.Dynamic.Core.CustomTypeProviders;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.TestClasses;
4+
5+
[DynamicLinqType]
6+
internal class TestClassWithDynamicLinqAttribute
7+
{
8+
}

0 commit comments

Comments
 (0)