From cf369fe3e76495e66670fb32af4e20ccd2f28be1 Mon Sep 17 00:00:00 2001 From: Stef Date: Tue, 11 Feb 2025 17:53:45 +0100 Subject: [PATCH] Fix AbstractDynamicLinqCustomTypeProvider.ResolveTypeBySimpleName to use AdditionalTypes --- .../AbstractDynamicLinqCustomTypeProvider.cs | 9 ++---- ...faultDynamicLinqCustomTypeProviderTests.cs | 31 +++++++++++++++++++ .../TestClassWithDynamicLinqAttribute.cs | 8 +++++ 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 test/System.Linq.Dynamic.Core.Tests/TestClasses/TestClassWithDynamicLinqAttribute.cs diff --git a/src/System.Linq.Dynamic.Core/CustomTypeProviders/AbstractDynamicLinqCustomTypeProvider.cs b/src/System.Linq.Dynamic.Core/CustomTypeProviders/AbstractDynamicLinqCustomTypeProvider.cs index cccb56c4..370ac349 100644 --- a/src/System.Linq.Dynamic.Core/CustomTypeProviders/AbstractDynamicLinqCustomTypeProvider.cs +++ b/src/System.Linq.Dynamic.Core/CustomTypeProviders/AbstractDynamicLinqCustomTypeProvider.cs @@ -66,16 +66,11 @@ protected Type[] FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumerable t.FullName!).Distinct().ToArray(); var firstMatchingFullname = fullNames.FirstOrDefault(fn => fn.EndsWith($".{simpleTypeName}")); - if (firstMatchingFullname == null) - { - return null; - } - - return types.FirstOrDefault(t => t.FullName == firstMatchingFullname); + return firstMatchingFullname == null ? null : types.FirstOrDefault(t => t.FullName == firstMatchingFullname); } #if (UAP10_0 || NETSTANDARD) diff --git a/test/System.Linq.Dynamic.Core.Tests/CustomTypeProviders/DefaultDynamicLinqCustomTypeProviderTests.cs b/test/System.Linq.Dynamic.Core.Tests/CustomTypeProviders/DefaultDynamicLinqCustomTypeProviderTests.cs index 1b9867b0..2db7721d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/CustomTypeProviders/DefaultDynamicLinqCustomTypeProviderTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/CustomTypeProviders/DefaultDynamicLinqCustomTypeProviderTests.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq.Dynamic.Core.CustomTypeProviders; +using System.Linq.Dynamic.Core.Tests.TestClasses; using FluentAssertions; using NFluent; using Xunit; @@ -61,4 +62,34 @@ public void DefaultDynamicLinqCustomTypeProvider_ResolveType_DefinedReturnsType( // Assert Check.That(result).IsNotNull(); } + + [Fact] + public void DefaultDynamicLinqCustomTypeProvider_ResolveTypeBySimpleName_UsesAdditionalTypes() + { + // Act + var result = _sut.ResolveTypeBySimpleName(nameof(TestClassWithDynamicLinqAttribute)); + + // Assert + Check.That(result).IsNotNull(); + } + + [Fact] + public void DefaultDynamicLinqCustomTypeProvider_ResolveTypeBySimpleName_UsesTypesMarkedWithDynamicLinqTypeAttribute() + { + // Act + var result = _sut.ResolveTypeBySimpleName(nameof(DirectoryInfo)); + + // Assert + Check.That(result).IsNotNull(); + } + + [Fact] + public void DefaultDynamicLinqCustomTypeProvider_ResolveTypeBySimpleName_UnknownReturnsNull() + { + // Act + var result = _sut.ResolveTypeBySimpleName("Dummy123"); + + // Assert + Check.That(result).IsNull(); + } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/TestClasses/TestClassWithDynamicLinqAttribute.cs b/test/System.Linq.Dynamic.Core.Tests/TestClasses/TestClassWithDynamicLinqAttribute.cs new file mode 100644 index 00000000..b5cf95b8 --- /dev/null +++ b/test/System.Linq.Dynamic.Core.Tests/TestClasses/TestClassWithDynamicLinqAttribute.cs @@ -0,0 +1,8 @@ +using System.Linq.Dynamic.Core.CustomTypeProviders; + +namespace System.Linq.Dynamic.Core.Tests.TestClasses; + +[DynamicLinqType] +internal class TestClassWithDynamicLinqAttribute +{ +} \ No newline at end of file