@@ -553,9 +553,10 @@ void ParseFilter(DynamicFilterLogic logic, DynamicFilterInfo fi, bool isend)
553553 if ( string . IsNullOrWhiteSpace ( fiValueCustomArray [ 0 ] ) ) throw new ArgumentException ( "Custom {静态方法名}不能为空,格式:{静态方法名}{空格}{反射信息}" ) ;
554554 if ( string . IsNullOrWhiteSpace ( fiValueCustomArray [ 1 ] ) ) throw new ArgumentException ( "Custom {反射信息}不能为空,格式:{静态方法名}{空格}{反射信息}" ) ;
555555 var fiValue1Type = Type . GetType ( fiValueCustomArray [ 1 ] ) ;
556- if ( fiValue1Type == null ) throw new ArgumentException ( $ "Custom 找到对应的 {{反射信息}}:{ fiValueCustomArray [ 1 ] } ") ;
556+ if ( fiValue1Type == null ) throw new ArgumentException ( $ "Custom 找不到对应的 {{反射信息}}:{ fiValueCustomArray [ 1 ] } ") ;
557557 var fiValue0Method = fiValue1Type . GetMethod ( fiValueCustomArray [ 0 ] , new Type [ ] { typeof ( string ) } ) ;
558- if ( fiValue0Method == null ) throw new ArgumentException ( $ "Custom 找到对应的{{静态方法名}}:{ fiValueCustomArray [ 0 ] } ") ;
558+ if ( fiValue0Method == null ) throw new ArgumentException ( $ "Custom 找不到对应的{{静态方法名}}:{ fiValueCustomArray [ 0 ] } ") ;
559+ if ( MethodIsDynamicFilterCustomAttribute ( fiValue0Method ) == false ) throw new ArgumentException ( $ "Custom 对应的{{静态方法名}}:{ fiValueCustomArray [ 0 ] } 未设置 [DynamicFilterCustomAttribute] 特性") ;
559560 var fiValue0MethodReturn = fiValue0Method ? . Invoke ( null , new object [ ] { fi . Value ? . ToString ( ) } ) ? . ToString ( ) ;
560561 exp = Expression . Call ( typeof ( SqlExt ) . GetMethod ( "InternalRawSql" , BindingFlags . NonPublic | BindingFlags . Static ) , Expression . Constant ( fiValue0MethodReturn , typeof ( string ) ) ) ;
561562 break ;
@@ -693,6 +694,21 @@ bool IsIgnoreFilter(DynamicFilterInfo testFilter)
693694 string . IsNullOrEmpty ( testFilter . Value ? . ToString ( ) ) ;
694695 }
695696 }
697+ static ConcurrentDictionary < MethodInfo , bool > _dicMethodIsDynamicFilterCustomAttribute = new ConcurrentDictionary < MethodInfo , bool > ( ) ;
698+ static bool MethodIsDynamicFilterCustomAttribute ( MethodInfo method ) => _dicMethodIsDynamicFilterCustomAttribute . GetOrAdd ( method , m =>
699+ {
700+ object [ ] attrs = null ;
701+ try
702+ {
703+ attrs = m . GetCustomAttributes ( false ) . ToArray ( ) ; //.net core 反射存在版本冲突问题,导致该方法异常
704+ }
705+ catch { }
706+
707+ var dyattr = attrs ? . Where ( a => {
708+ return ( ( a as Attribute ) ? . TypeId as Type ) ? . Name == "DynamicFilterCustomAttribute" ;
709+ } ) . FirstOrDefault ( ) ;
710+ return dyattr != null ;
711+ } ) ;
696712
697713 public TSelect DisableGlobalFilter ( params string [ ] name )
698714 {
0 commit comments