1
1
using LogicBuilder . Expressions . Utils ;
2
2
using Microsoft . AspNetCore . OData . Edm ;
3
- using Microsoft . AspNetCore . OData . Query ;
4
3
using Microsoft . OData . Edm ;
5
4
using Microsoft . OData . ModelBuilder ;
6
5
using System ;
7
6
using System . Collections . Generic ;
8
- using System . ComponentModel . DataAnnotations ;
9
- using System . Diagnostics ;
10
7
using System . Linq ;
11
8
using System . Reflection ;
12
9
@@ -21,6 +18,17 @@ public static MemberInfo[] GetSelectedMembers(this Type parentType, List<string>
21
18
22
19
return selects . Select ( select => parentType . GetMemberInfo ( select ) ) . ToArray ( ) ;
23
20
}
21
+
22
+ public static IEnumerable < string > GetLiteralLists ( this Type type )
23
+ {
24
+ foreach ( var member in type . GetMemberInfos ( ) )
25
+ {
26
+ if ( member . MemberType is not ( MemberTypes . Field or MemberTypes . Property ) ) continue ;
27
+
28
+ if ( member . GetMemberType ( ) . IsListLiteral ( ) )
29
+ yield return member . Name ;
30
+ }
31
+ }
24
32
25
33
private static MemberInfo [ ] GetValueTypeMembers ( this Type parentType )
26
34
{
@@ -33,6 +41,19 @@ private static MemberInfo[] GetValueTypeMembers(this Type parentType)
33
41
&& info . GetMemberType ( ) . IsLiteralType ( )
34
42
) . ToArray ( ) ;
35
43
}
44
+
45
+ private static bool IsListLiteral ( this Type type )
46
+ {
47
+ // Check if type is a List
48
+ if ( ! type . IsList ( ) ) return false ;
49
+
50
+ // If not generic, check if it's a literal type (i.e. string[])
51
+ if ( ! type . IsGenericType ) return type . GetElementType ( ) . IsLiteralType ( ) ;
52
+
53
+ // Extract the type T from List<T> and check if it's a literal type
54
+ var firstGenericArgument = type . GetGenericArguments ( ) . First ( ) ;
55
+ return firstGenericArgument . IsLiteralType ( ) ;
56
+ }
36
57
37
58
private static MemberInfo [ ] GetMemberInfos ( this Type parentType )
38
59
=> parentType . GetMembers ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . FlattenHierarchy | BindingFlags . IgnoreCase ) ;
0 commit comments