Skip to content

Commit 586ba45

Browse files
authored
Add support for methods on Enum (#714)
* Add support for methods on Enum * public class PredefinedTypesHelperTests * xxxxxxxxxxxxxxxxxxx
1 parent 4cc72c4 commit 586ba45

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ internal static class PredefinedTypesHelper
2323
{ "float", typeof(float) }
2424
};
2525

26-
public static readonly IDictionary<Type, int> PredefinedTypes = new ConcurrentDictionary<Type, int>(new Dictionary<Type, int> {
26+
public static readonly IDictionary<Type, int> PredefinedTypes = new ConcurrentDictionary<Type, int>(new Dictionary<Type, int>
27+
{
2728
{ typeof(object), 0 },
2829
{ typeof(bool), 0 },
2930
{ typeof(char), 0 },
@@ -46,6 +47,7 @@ internal static class PredefinedTypesHelper
4647
{ typeof(Math), 0 },
4748
{ typeof(Convert), 0 },
4849
{ typeof(Uri), 0 },
50+
{ typeof(Enum), 0 },
4951
#if NET6_0_OR_GREATER
5052
{ typeof(DateOnly), 0 },
5153
{ typeof(TimeOnly), 0 }

test/System.Linq.Dynamic.Core.Tests/Parser/DynamicLinqTypeTest.cs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Linq.Dynamic.Core.CustomTypeProviders;
2+
using FluentAssertions;
23
using NFluent;
34
using Xunit;
45

@@ -51,6 +52,18 @@ public class EntityValue
5152
public int ValueInt { get; set; }
5253
}
5354

55+
[Flags]
56+
public enum Status
57+
{
58+
Inactive = 0,
59+
60+
Active = 1,
61+
62+
Other = 2,
63+
64+
ActiveOther = 3
65+
}
66+
5467

5568
[Fact]
5669
public void ParamArray_EmptyValue()
@@ -168,5 +181,19 @@ public void ExtensionMethod_SingleParameter()
168181
Check.That(result[0]).Equals(6);
169182
Check.That(result[1]).Equals(7);
170183
}
184+
185+
[Fact]
186+
public void CallMethodOnEnum()
187+
{
188+
// Arrange
189+
var queryable = new[] { Status.Active, Status.ActiveOther, Status.Inactive }.AsQueryable();
190+
191+
// Act
192+
var status = Status.Active;
193+
var result = queryable.Where("@0.HasFlag(it)", status).ToDynamicArray<Status>();
194+
195+
// Assert
196+
result.Should().HaveCount(2);
197+
}
171198
}
172-
}
199+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Linq.Dynamic.Core.Parser;
2+
using FluentAssertions;
3+
using Xunit;
4+
5+
namespace System.Linq.Dynamic.Core.Tests.Parser;
6+
7+
public class PredefinedTypesHelperTests
8+
{
9+
[Fact]
10+
public void IsPredefinedType_ShouldReturnFalse_ForNonPredefinedTypes()
11+
{
12+
// Arrange
13+
var config = new ParsingConfig();
14+
15+
// Act & Assert
16+
PredefinedTypesHelper.IsPredefinedType(config, typeof(IO.File)).Should().BeFalse();
17+
}
18+
19+
[Fact]
20+
public void IsPredefinedType_ShouldReturnTrue_ForPredefinedTypes()
21+
{
22+
// Arrange
23+
var config = new ParsingConfig();
24+
var predefinedTypes = PredefinedTypesHelper.PredefinedTypes.Keys;
25+
26+
// Act & Assert
27+
foreach (var predefinedType in predefinedTypes)
28+
{
29+
PredefinedTypesHelper.IsPredefinedType(config, predefinedType).Should().BeTrue();
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)