Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CVE-2024-51417 #870

Merged
merged 8 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Dynamic.Core.Extensions;
using System.Linq.Dynamic.Core.Validation;
using System.Reflection;

Expand All @@ -13,11 +12,25 @@ namespace System.Linq.Dynamic.Core.CustomTypeProviders;
public abstract class AbstractDynamicLinqCustomTypeProvider
{
/// <summary>
/// Finds the unique types marked with DynamicLinqTypeAttribute.
/// Additional types which should also be resolved.
/// </summary>
protected readonly IList<Type> AdditionalTypes;

/// <summary>
/// Initializes a new instance of the <see cref="AbstractDynamicLinqCustomTypeProvider"/> class.
/// </summary>
/// <param name="additionalTypes">A list of additional types (without the DynamicLinqTypeAttribute annotation) which should also be resolved.</param>
protected AbstractDynamicLinqCustomTypeProvider(IList<Type> additionalTypes)
{
AdditionalTypes = Check.NotNull(additionalTypes);
}

/// <summary>
/// Finds the unique types annotated with DynamicLinqTypeAttribute.
/// </summary>
/// <param name="assemblies">The assemblies to process.</param>
/// <returns><see cref="IEnumerable{Type}" /></returns>
protected IEnumerable<Type> FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumerable<Assembly> assemblies)
protected Type[] FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumerable<Assembly> assemblies)
{
Check.NotNull(assemblies);
#if !NET35
Expand All @@ -27,7 +40,7 @@ protected IEnumerable<Type> FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumera
}

/// <summary>
/// Resolve any type which is registered in the current application domain.
/// Resolve a type which is annotated with DynamicLinqTypeAttribute or when the type is listed in AdditionalTypes.
/// </summary>
/// <param name="assemblies">The assemblies to inspect.</param>
/// <param name="typeName">The typename to resolve.</param>
Expand All @@ -37,20 +50,13 @@ protected IEnumerable<Type> FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumera
Check.NotNull(assemblies);
Check.NotEmpty(typeName);

foreach (var assembly in assemblies)
{
var resolvedType = assembly.GetType(typeName, false, true);
if (resolvedType != null)
{
return resolvedType;
}
}

return null;
var types = FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies).Union(AdditionalTypes);
return types.FirstOrDefault(t => t.FullName == typeName);
}

/// <summary>
/// Resolve a type by the simple name which is registered in the current application domain.
/// Resolve a type which is annotated with DynamicLinqTypeAttribute by the simple (short) name.
/// Also when the type is listed in AdditionalTypes.
/// </summary>
/// <param name="assemblies">The assemblies to inspect.</param>
/// <param name="simpleTypeName">The simple typename to resolve.</param>
Expand All @@ -60,22 +66,16 @@ protected IEnumerable<Type> FindTypesMarkedWithDynamicLinqTypeAttribute(IEnumera
Check.NotNull(assemblies);
Check.NotEmpty(simpleTypeName);

foreach (var assembly in assemblies)
{
var fullNames = assembly.GetTypes().Select(t => t.FullName!).Distinct();
var firstMatchingFullname = fullNames.FirstOrDefault(fn => fn.EndsWith($".{simpleTypeName}"));
var types = FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies);
var fullNames = types.Select(t => t.FullName!).Distinct().ToArray();
var firstMatchingFullname = fullNames.FirstOrDefault(fn => fn.EndsWith($".{simpleTypeName}"));

if (firstMatchingFullname != null)
{
var resolvedType = assembly.GetType(firstMatchingFullname, false, true);
if (resolvedType != null)
{
return resolvedType;
}
}
if (firstMatchingFullname == null)
{
return null;
}

return null;
return types.FirstOrDefault(t => t.FullName == firstMatchingFullname);
}

#if (UAP10_0 || NETSTANDARD)
Expand Down Expand Up @@ -147,7 +147,7 @@ protected Type[] GetAssemblyTypesWithDynamicLinqTypeAttribute(IEnumerable<Assemb
}
catch (ReflectionTypeLoadException reflectionTypeLoadException)
{
definedTypes = reflectionTypeLoadException.Types.WhereNotNull().ToArray();
definedTypes = reflectionTypeLoadException.Types.OfType<Type>().ToArray();
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
///
/// Scans the current AppDomain for all types marked with <see cref="DynamicLinqTypeAttribute"/>, and adds them as custom Dynamic Link types.
///
/// Also provides functionality to resolve a Type in the current Application Domain.
///
/// This class is used as default for full .NET Framework and .NET Core App 2.x and higher.
/// </summary>
public class DefaultDynamicLinqCustomTypeProvider : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider

Check warning on line 15 in src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 15 in src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 15 in src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 15 in src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 15 in src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 15 in src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'
{
private readonly IAssemblyHelper _assemblyHelper;
private readonly bool _cacheCustomTypes;
Expand All @@ -22,12 +20,12 @@
private HashSet<Type>? _cachedCustomTypes;
private Dictionary<Type, List<MethodInfo>>? _cachedExtensionMethods;

/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="DefaultDynamicLinqCustomTypeProvider"/> class.
/// Backwards compatibility for issue https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/830.
/// </summary>
/// <param name="cacheCustomTypes">Defines whether to cache the CustomTypes (including extension methods) which are found in the Application Domain. Default set to 'true'.</param>
[Obsolete("Please use the DefaultDynamicLinqCustomTypeProvider(ParsingConfig config, bool cacheCustomTypes = true) constructor.")]
[Obsolete("Please use the DefaultDynamicLinqCustomTypeProvider(ParsingConfig config, IList<Type> additionalTypes, bool cacheCustomTypes = true) constructor.")]
public DefaultDynamicLinqCustomTypeProvider(bool cacheCustomTypes = true) : this(ParsingConfig.Default, cacheCustomTypes)
{
}
Expand All @@ -37,7 +35,17 @@
/// </summary>
/// <param name="config">The parsing configuration.</param>
/// <param name="cacheCustomTypes">Defines whether to cache the CustomTypes (including extension methods) which are found in the Application Domain. Default set to 'true'.</param>
public DefaultDynamicLinqCustomTypeProvider(ParsingConfig config, bool cacheCustomTypes = true)
public DefaultDynamicLinqCustomTypeProvider(ParsingConfig config, bool cacheCustomTypes = true) : this(config, new List<Type>(), cacheCustomTypes)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="DefaultDynamicLinqCustomTypeProvider"/> class.
/// </summary>
/// <param name="config">The parsing configuration.</param>
/// <param name="additionalTypes">A list of additional types (without the DynamicLinqTypeAttribute annotation) which should also be resolved.</param>
/// <param name="cacheCustomTypes">Defines whether to cache the CustomTypes (including extension methods) which are found in the Application Domain. Default set to 'true'.</param>
public DefaultDynamicLinqCustomTypeProvider(ParsingConfig config, IList<Type> additionalTypes, bool cacheCustomTypes = true) : base(additionalTypes)
{
_assemblyHelper = new DefaultAssemblyHelper(Check.NotNull(config));
_cacheCustomTypes = cacheCustomTypes;
Expand Down Expand Up @@ -96,7 +104,8 @@
private HashSet<Type> GetCustomTypesInternal()
{
IEnumerable<Assembly> assemblies = _assemblyHelper.GetAssemblies();
return new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies));
var types = FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies).Union(AdditionalTypes);
return new HashSet<Type>(types);
}

private Dictionary<Type, List<MethodInfo>> GetExtensionMethodsInternal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
/// <summary>
/// Interface for providing functionality to find custom types for or resolve any type.
/// Note that this interface will be marked obsolete in the next version. Use <see cref="IDynamicLinqCustomTypeProvider"/> instead.
/// </summary>
[Obsolete("Please use the IDynamicLinqCustomTypeProvider interface instead.")]
public interface IDynamicLinkCustomTypeProvider : IDynamicLinqCustomTypeProvider
{
}
}
}
16 changes: 0 additions & 16 deletions src/System.Linq.Dynamic.Core/Extensions/LinqExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static class PredefinedTypesHelper

public static readonly IDictionary<Type, int> PredefinedTypes = new ConcurrentDictionary<Type, int>(new Dictionary<Type, int>
{
{ typeof(object), 0 },
// { typeof(object), 0 }, Removed because of CVE-2024-51417
{ typeof(bool), 0 },
{ typeof(char), 0 },
{ typeof(string), 0 },
Expand Down
19 changes: 19 additions & 0 deletions src/System.Linq.Dynamic.Core/ParsingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// </summary>
public class ParsingConfig
{
private IDynamicLinkCustomTypeProvider? _customTypeProvider;

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 16 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'
private IExpressionPromoter? _expressionPromoter;
private IQueryableAnalyzer? _queryableAnalyzer;

Expand Down Expand Up @@ -54,7 +54,7 @@
/// <summary>
/// Gets or sets the <see cref="IDynamicLinkCustomTypeProvider"/>.
/// </summary>
public IDynamicLinkCustomTypeProvider? CustomTypeProvider

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Windows: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'

Check warning on line 57 in src/System.Linq.Dynamic.Core/ParsingConfig.cs

View workflow job for this annotation

GitHub Actions / Linux: Build and Tests

'IDynamicLinkCustomTypeProvider' is obsolete: 'Please use the IDynamicLinqCustomTypeProvider interface instead.'
{
get
{
Expand All @@ -71,6 +71,25 @@
}
}

/// <summary>
/// Sets the CustomTypeProvider to <see cref="DefaultDynamicLinqCustomTypeProvider"/>.
/// </summary>
/// <param name="cacheCustomTypes">Defines whether to cache the CustomTypes (including extension methods) which are found in the Application Domain. Default set to <c>true</c>.</param>
public void UseDefaultDynamicLinqCustomTypeProvider(bool cacheCustomTypes = true)
{
_customTypeProvider = new DefaultDynamicLinqCustomTypeProvider(this, cacheCustomTypes);
}

/// <summary>
/// Sets the CustomTypeProvider to <see cref="DefaultDynamicLinqCustomTypeProvider"/>.
/// </summary>
/// <param name="cacheCustomTypes">Defines whether to cache the CustomTypes (including extension methods) which are found in the Application Domain. Default set to <c>true</c>.</param>
/// <param name="additionalTypes">A list of additional types (without the DynamicLinqTypeAttribute annotation) which should also be resolved.</param>
public void UseDefaultDynamicLinqCustomTypeProvider(IList<Type> additionalTypes, bool cacheCustomTypes = true)
{
_customTypeProvider = new DefaultDynamicLinqCustomTypeProvider(this, additionalTypes, cacheCustomTypes);
}

/// <summary>
/// Load additional assemblies from the current domain base directory.
/// Note: only used when full .NET Framework and .NET Core App 2.x and higher.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq.Dynamic.Core.CustomTypeProviders;
using FluentAssertions;
using NFluent;
Expand All @@ -8,11 +9,17 @@ namespace System.Linq.Dynamic.Core.Tests.CustomTypeProviders;

public class DefaultDynamicLinqCustomTypeProviderTests
{
private readonly IList<Type> _additionalTypes = new List<Type>
{
typeof(DirectoryInfo),
typeof(DefaultDynamicLinqCustomTypeProviderTests)
};

private readonly DefaultDynamicLinqCustomTypeProvider _sut;

public DefaultDynamicLinqCustomTypeProviderTests()
{
_sut = new DefaultDynamicLinqCustomTypeProvider(ParsingConfig.Default);
_sut = new DefaultDynamicLinqCustomTypeProvider(ParsingConfig.Default, _additionalTypes);
}

[Fact]
Expand Down
3 changes: 2 additions & 1 deletion test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ public void DynamicClassArray_Issue593_Fails()
isValid.Should().BeFalse(); // This should actually be true, but fails. For solution see Issue593_Solution1 and Issue593_Solution2.
}

[SkipIfGitHubActions]
// [SkipIfGitHubActions]
[Fact(Skip = "867")]
public void DynamicClassArray_Issue593_Solution1()
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ public void DynamicExpressionParser_ParseLambda_StringLiteral_QuotationMark()
Assert.Equal(expectedRightValue, rightValue);
}

[Fact]
[Fact(Skip = "867")]
public void DynamicExpressionParser_ParseLambda_TupleToStringMethodCall_ReturnsStringLambdaExpression()
{
var expression = DynamicExpressionParser.ParseLambda(
Expand Down
5 changes: 4 additions & 1 deletion test/System.Linq.Dynamic.Core.Tests/Entities/Worker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace System.Linq.Dynamic.Core.Tests.Entities
using System.Linq.Dynamic.Core.CustomTypeProviders;

namespace System.Linq.Dynamic.Core.Tests.Entities
{
[DynamicLinqType]
public class Worker : BaseEmployee
{
public string Other { get; set; }
Expand Down
14 changes: 11 additions & 3 deletions test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace System.Linq.Dynamic.Core.Tests
{
[DynamicLinqType]
public enum TestEnumPublic : sbyte
{
Var1 = 0,
Expand All @@ -25,6 +26,7 @@ public enum TestEnumPublic : sbyte

public partial class ExpressionTests
{
[DynamicLinqType]
public enum TestEnum2 : sbyte
{
Var1 = 0,
Expand Down Expand Up @@ -919,6 +921,9 @@ public void ExpressionTests_Enum_Property_Equality_Using_PublicEnum_And_FullName
public void ExpressionTests_Enum_Property_Equality_Using_Enum_And_FullName_Inline()
{
// Arrange
var config = new ParsingConfig();
config.UseDefaultDynamicLinqCustomTypeProvider([typeof(TestEnum2)]);

var qry = new List<TestEnumClass> { new TestEnumClass { B = TestEnum2.Var2 } }.AsQueryable();
string enumType = typeof(TestEnum2).FullName!;

Expand Down Expand Up @@ -948,7 +953,7 @@ public void ExpressionTests_Enum_Property_Equality_Using_PublicEnum_Name_Inline(
}

[Fact]
public void ExpressionTests_Enum_Property_Equality_Using_Enum_Name_Inline_Should_Throw_Exception()
public void ExpressionTests_Enum_Property_Equality_Using_Enum_Name_Inline_ShouldBeOk()
{
// Arrange
var config = new ParsingConfig
Expand All @@ -962,7 +967,7 @@ public void ExpressionTests_Enum_Property_Equality_Using_Enum_Name_Inline_Should
Action a = () => qry.Where(config, $"{enumType}.Var2 == it.B").ToDynamicArray();

// Assert
a.Should().Throw<Exception>();
a.Should().NotThrow();
}

[Fact]
Expand Down Expand Up @@ -1031,7 +1036,10 @@ public void ExpressionTests_Enum_NullableProperty()
[Fact]
public void ExpressionTests_Enum_MoreTests()
{
var config = new ParsingConfig();
var config = new ParsingConfig
{
ResolveTypesBySimpleName = true
};

// Arrange
var lst = new List<TestEnum> { TestEnum.Var1, TestEnum.Var2, TestEnum.Var3, TestEnum.Var4, TestEnum.Var5, TestEnum.Var6 };
Expand Down
45 changes: 45 additions & 0 deletions test/System.Linq.Dynamic.Core.Tests/Helpers/Models/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;
using System.Linq.Dynamic.Core.CustomTypeProviders;

namespace System.Linq.Dynamic.Core.Tests.Helpers.Models
{
public static class AppSettings
{
public static Dictionary<string, string> SettingsProp { get; } = new()
{
{ "jwt", "test" }
};

public static Dictionary<string, string> SettingsField = new()
{
{ "jwt", "test" }
};
}

[DynamicLinqType]
public static class AppSettings2
{
public static Dictionary<string, string> SettingsProp { get; } = new()
{
{ "jwt", "test" }
};

public static Dictionary<string, string> SettingsField = new()
{
{ "jwt", "test" }
};
}

public class AppSettings3
{
public static Dictionary<string, string> SettingsProp { get; } = new()
{
{ "jwt", "test" }
};

public static Dictionary<string, string> SettingsField = new()
{
{ "jwt", "test" }
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void Parse_NullableShouldReturnNullable(string expression, object resultT
[Theory]
[InlineData("it.MainCompany.Name != null", "(company.MainCompany.Name != null)")]
[InlineData("@MainCompany.Companies.Count() > 0", "(company.MainCompany.Companies.Count() > 0)")]
[InlineData("Company.Equals(null, null)", "Equals(null, null)")]
// [InlineData("Company.Equals(null, null)", "Equals(null, null)")] issue 867
[InlineData("MainCompany.Name", "company.MainCompany.Name")]
[InlineData("Name", "company.Name")]
[InlineData("company.Name", "company.Name")]
Expand Down
Loading
Loading