@@ -6,12 +6,13 @@ namespace System.Linq.Dynamic.Core.Parser;
66
77internal class PredefinedMethodsHelper
88{
9- private static readonly BindingFlags _bindingFlags = BindingFlags . Public | BindingFlags . Instance ;
9+ private static readonly BindingFlags _publicInstance = BindingFlags . Public | BindingFlags . Instance ;
10+ private static readonly BindingFlags _publicStatic = BindingFlags . Public | BindingFlags . Static ;
1011
11- internal static readonly MethodInfo ObjectInstanceToString = typeof ( object ) . GetMethod ( nameof ( ToString ) , _bindingFlags , null , Type . EmptyTypes , null ) ! ;
12- internal static readonly MethodInfo ObjectInstanceEquals = typeof ( object ) . GetMethod ( nameof ( Equals ) , _bindingFlags , null , [ typeof ( object ) ] , null ) ! ;
13- internal static readonly MethodInfo ObjectStaticEquals = typeof ( object ) . GetMethod ( nameof ( Equals ) , BindingFlags . Static | BindingFlags . Public , null , [ typeof ( object ) , typeof ( object ) ] , null ) ! ;
14- internal static readonly MethodInfo ObjectStaticReferenceEquals = typeof ( object ) . GetMethod ( nameof ( ReferenceEquals ) , BindingFlags . Static | BindingFlags . Public , null , [ typeof ( object ) , typeof ( object ) ] , null ) ! ;
12+ internal static readonly MethodInfo ObjectInstanceToString = typeof ( object ) . GetMethod ( nameof ( ToString ) , _publicInstance , null , Type . EmptyTypes , null ) ! ;
13+ internal static readonly MethodInfo ObjectInstanceEquals = typeof ( object ) . GetMethod ( nameof ( Equals ) , _publicInstance , null , [ typeof ( object ) ] , null ) ! ;
14+ internal static readonly MethodInfo ObjectStaticEquals = typeof ( object ) . GetMethod ( nameof ( Equals ) , _publicStatic , null , [ typeof ( object ) , typeof ( object ) ] , null ) ! ;
15+ internal static readonly MethodInfo ObjectStaticReferenceEquals = typeof ( object ) . GetMethod ( nameof ( ReferenceEquals ) , _publicStatic , null , [ typeof ( object ) , typeof ( object ) ] , null ) ! ;
1516
1617 private readonly Dictionary < Type , HashSet < MemberInfo > > _supported = new ( )
1718 {
@@ -29,31 +30,31 @@ internal class PredefinedMethodsHelper
2930 { typeof ( float ) , new HashSet < MemberInfo > ( ) } ,
3031 { typeof ( double ) , new HashSet < MemberInfo > ( ) } ,
3132 { typeof ( decimal ) , new HashSet < MemberInfo > ( ) } ,
32- // { typeof(DateTime), new HashSet<MemberInfo>() },
33- // { typeof(DateTimeOffset), new HashSet<MemberInfo>() },
34- // { typeof(TimeSpan), new HashSet<MemberInfo>() },
35- // { typeof(Guid), new HashSet<MemberInfo>() },
36- // { typeof(Uri), new HashSet<MemberInfo>() },
37- // { typeof(Enum), new HashSet<MemberInfo>() },
33+ { typeof ( DateTime ) , new HashSet < MemberInfo > ( ) } ,
34+ { typeof ( DateTimeOffset ) , new HashSet < MemberInfo > ( ) } ,
35+ { typeof ( TimeSpan ) , new HashSet < MemberInfo > ( ) } ,
36+ { typeof ( Guid ) , new HashSet < MemberInfo > ( ) } ,
37+ { typeof ( Uri ) , new HashSet < MemberInfo > ( ) } ,
38+ { typeof ( Enum ) , new HashSet < MemberInfo > ( ) } ,
3839#if NET6_0_OR_GREATER
39- // { typeof(DateOnly), new HashSet<MemberInfo>() },
40- // { typeof(TimeOnly), new HashSet<MemberInfo>() },
40+ { typeof ( DateOnly ) , new HashSet < MemberInfo > ( ) } ,
41+ { typeof ( TimeOnly ) , new HashSet < MemberInfo > ( ) } ,
4142#endif
4243 } ;
4344
4445 public PredefinedMethodsHelper ( ParsingConfig config )
4546 {
4647 foreach ( var kvp in _supported )
4748 {
48- Add ( kvp . Key , ObjectInstanceEquals ) ;
49- Add ( kvp . Key , kvp . Key . GetMethod ( nameof ( Equals ) , _bindingFlags , null , [ kvp . Key ] , null ) ) ;
50- Add ( kvp . Key , kvp . Key . GetMethod ( nameof ( Equals ) , _bindingFlags , null , [ typeof ( object ) ] , null ) ) ;
49+ TryAdd ( kvp . Key , ObjectInstanceEquals ) ;
50+ TryAdd ( kvp . Key , kvp . Key . GetMethod ( nameof ( Equals ) , _publicInstance , null , [ kvp . Key ] , null ) ) ;
51+ TryAdd ( kvp . Key , kvp . Key . GetMethod ( nameof ( Equals ) , _publicInstance , null , [ typeof ( object ) ] , null ) ) ;
5152
52- Add ( kvp . Key , ObjectInstanceToString ) ;
53- Add ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _bindingFlags , null , Type . EmptyTypes , null ) ) ;
54- Add ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _bindingFlags , null , [ typeof ( string ) ] , null ) ) ;
55- Add ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _bindingFlags , null , [ typeof ( IFormatProvider ) ] , null ) ) ;
56- Add ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _bindingFlags , null , [ typeof ( string ) , typeof ( IFormatProvider ) ] , null ) ) ;
53+ TryAdd ( kvp . Key , ObjectInstanceToString ) ;
54+ TryAdd ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _publicInstance , null , Type . EmptyTypes , null ) ) ;
55+ TryAdd ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _publicInstance , null , [ typeof ( string ) ] , null ) ) ;
56+ TryAdd ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _publicInstance , null , [ typeof ( IFormatProvider ) ] , null ) ) ;
57+ TryAdd ( kvp . Key , kvp . Key . GetMethod ( nameof ( ToString ) , _publicInstance , null , [ typeof ( string ) , typeof ( IFormatProvider ) ] , null ) ) ;
5758 }
5859
5960 if ( config . AllowEqualsAndToStringMethodsOnObject )
@@ -75,7 +76,7 @@ public bool IsPredefinedMethod(Type type, MemberInfo member)
7576 return supported . Contains ( member ) ;
7677 }
7778
78- private void Add ( Type type , MethodInfo ? method )
79+ private void TryAdd ( Type type , MethodInfo ? method )
7980 {
8081 if ( method != null )
8182 {
0 commit comments