@@ -63,29 +63,27 @@ IEnumerable<NodeSearchResult> GetPropertiesAndFields(TypeBase type, string text)
6363 // find if the method exists
6464 var methods = type . GetMethods ( ) . Where ( x => x . Name . Contains ( methodCallSplit [ ^ 1 ] , StringComparison . OrdinalIgnoreCase ) ) ;
6565
66+ // only keep the methods that are using the startConnection type, if provided
67+ if ( startConnection ? . Type ? . IsExec == false )
68+ methods = methods . Where ( x => x . GetParameters ( ) . Any ( y => startConnection . Type . IsAssignableTo ( y . ParameterType , out _ ) ) ) ;
69+
6670 results = results . Concat ( methods . Select ( x => new MethodCallNode ( typeof ( MethodCall ) , x ) ) ) ;
6771
68- results = results . Concat ( GetPropertiesAndFields ( type , methodCallSplit [ 1 ] ) ) ;
72+ if ( startConnection == null )
73+ results = results . Concat ( GetPropertiesAndFields ( type , methodCallSplit [ 1 ] ) ) ;
6974 }
7075 }
71- else if ( startConnection ? . Type is RealType realType )
76+ else if ( startConnection ? . Type . IsExec == false )
7277 {
7378 // find if the method exists
74- IEnumerable < MethodInfo > methods = realType . BackendType . GetMethods ( BindingFlags . Public | BindingFlags . FlattenHierarchy | BindingFlags . Instance ) ;
79+ var methods = startConnection . Type . GetMethods ( ) . Where ( x => x . Name . Contains ( text , StringComparison . OrdinalIgnoreCase ) && ! x . IsStatic ) ;
7580 // get extensions methods for the realType.BackendType
7681
77- methods = methods . Concat ( GetExtensionMethods ( realType , project . TypeFactory ) ) . Where ( x => string . IsNullOrWhiteSpace ( text ) || x . Name . Contains ( text , StringComparison . OrdinalIgnoreCase ) ) ;
78-
79- results = results . Concat ( methods . Select ( x => new MethodCallNode ( typeof ( MethodCall ) , new RealMethodInfo ( project . TypeFactory , x , realType ) ) ) ) ;
82+ methods = methods . Concat ( GetExtensionMethods ( startConnection . Type , project . TypeFactory ) ) . Where ( x => string . IsNullOrWhiteSpace ( text ) || x . Name . Contains ( text , StringComparison . OrdinalIgnoreCase ) ) ;
8083
81- results = results . Concat ( GetPropertiesAndFields ( realType , text ) ) ;
82- }
83- else if ( startConnection ? . Type is NodeClassType nodeClassType )
84- {
85- // get the properties in that object
86- results = results . Concat ( nodeClassType . NodeClass . Properties . Select ( x => new GetPropertyOrFieldNode ( typeof ( GetPropertyOrField ) , x ) ) ) ;
84+ results = results . Concat ( methods . Select ( x => new MethodCallNode ( typeof ( MethodCall ) , x ) ) ) ;
8785
88- results = results . Concat ( nodeClassType . NodeClass . Methods . Select ( x => new MethodCallNode ( typeof ( MethodCall ) , x ) ) ) ;
86+ results = results . Concat ( GetPropertiesAndFields ( startConnection . Type , text ) ) ;
8987 }
9088
9189 // add methods, get properties and set properties
@@ -105,18 +103,27 @@ IEnumerable<NodeSearchResult> GetPropertiesAndFields(TypeBase type, string text)
105103 return ( object ) result ;
106104 } ) ;
107105
108-
109106 return results ;
110107 }
111108
112- private static IEnumerable < MethodInfo > GetExtensionMethods ( TypeBase t , TypeFactory typeFactory )
109+ private static readonly Dictionary < Assembly , List < RealMethodInfo > > ExtensionMethodsMethodsPerType = [ ] ;
110+ private static IEnumerable < IMethodInfo > GetExtensionMethods ( TypeBase t , TypeFactory typeFactory )
113111 {
114112 var query = AppDomain . CurrentDomain . GetAssemblies ( )
115113 . Where ( x => ! x . IsDynamic ) // dirty patch to prevent loading types from the generated assemblies
116- . SelectMany ( x => x . GetTypes ( ) )
117- . Where ( type => ! type . IsGenericType )
118- . SelectMany ( type => type . GetMethods ( BindingFlags . Static | BindingFlags . Public | BindingFlags . NonPublic ) )
119- . Where ( method => method . IsDefined ( typeof ( ExtensionAttribute ) , false ) && t . IsAssignableTo ( typeFactory . Get ( method . GetParameters ( ) [ 0 ] . ParameterType , null ) , out _ ) ) ;
114+ . SelectMany ( assembly =>
115+ {
116+ if ( ExtensionMethodsMethodsPerType . TryGetValue ( assembly , out var methods ) )
117+ return methods ;
118+
119+ return ExtensionMethodsMethodsPerType [ assembly ] = assembly
120+ . GetTypes ( )
121+ . Where ( type => ! type . IsGenericType )
122+ . SelectMany ( x => x . GetMethods ( BindingFlags . Static | BindingFlags . Public | BindingFlags . NonPublic ) )
123+ . Where ( method => method . IsDefined ( typeof ( ExtensionAttribute ) , false ) && t . IsAssignableTo ( typeFactory . Get ( method . GetParameters ( ) [ 0 ] . ParameterType , null ) , out _ ) )
124+ . Select ( x => new RealMethodInfo ( typeFactory , x , typeFactory . Get ( x . DeclaringType ! , null ) ) )
125+ . ToList ( ) ;
126+ } ) ;
120127
121128 return query ;
122129 }
0 commit comments