Skip to content

Commit 52acb73

Browse files
committed
Merge branch 'master' into stef-PredefinedMethodsHelper
2 parents 3f92c1c + 1fa3e15 commit 52acb73

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class MyCustomClass
4747
}
4848
```
4949
If it's not possible to add that attribute, you need to implement a custom [CustomTypeProvider](https://dynamic-linq.net/advanced-configuration#customtypeprovider) and set this to the `ParsingConfig` and provide that config to all dynamic calls.
50-
Or provide a list of addtional types in the [DefaultDynamicLinqCustomTypeProvider.cs](https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs).
50+
Or provide a list of additional types in the [DefaultDynamicLinqCustomTypeProvider.cs](https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs).
5151

5252
### v1.6.0
5353
#### Change 1
@@ -61,6 +61,11 @@ Which means that only properties and fields can be used in the `OrderBy` / `Then
6161
This is done to mitigate the risk of calling methods or other expressions in the `OrderBy` / `ThenBy` which could lead to security issues.
6262
To allow these methods set `RestrictOrderByToPropertyOrField` to `false` in the `ParsingConfig` and provide that config to all dynamic calls.
6363

64+
#### Change 3
65+
The `DefaultDynamicLinqCustomTypeProvider` has been changed to only return types which have the `[DynamicLinqType]` attribute applied.
66+
If it's not possible to add that attribute, you need to implement a custom [CustomTypeProvider](https://dynamic-linq.net/advanced-configuration#customtypeprovider) and set this to the `ParsingConfig` and provide that config to all dynamic calls.
67+
Or provide a list of additional types in the [DefaultDynamicLinqCustomTypeProvider.cs](https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs).
68+
6469
---
6570

6671
## Useful links

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

Lines changed: 2 additions & 7 deletions
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

Lines changed: 31 additions & 0 deletions
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
}
Lines changed: 8 additions & 0 deletions
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)