Beispiel #1
0
        private IMethodSymbol GetMethodInfoFromSpecifier(MethodSpecifier specifier)
        {
            INamedTypeSymbol declaringType = GetTypeFromSpecifier <INamedTypeSymbol>(specifier.DeclaringType);

            return(declaringType?.GetMethods().FirstOrDefault(
                       m => m.Name == specifier.Name &&
                       m.Parameters.Select(p => ReflectionConverter.BaseTypeSpecifierFromSymbol(p.Type)).SequenceEqual(specifier.ArgumentTypes)));
        }
Beispiel #2
0
        public IEnumerable <MethodSpecifier> GetStaticFunctionsWithArgumentType(TypeSpecifier searchTypeSpec)
        {
            // Find all public static methods

            IEnumerable <IMethodSymbol> availableMethods = GetValidTypes()
                                                           .Where(t => t.IsPublic())
                                                           .SelectMany(t =>
                                                                       t.GetMethods()
                                                                       .Where(m => m.IsPublic() && m.IsStatic && !m.ContainingType.IsUnboundGenericType))
                                                           .OrderBy(m => m?.ContainingNamespace.Name)
                                                           .ThenBy(m => m?.ContainingType.Name)
                                                           .ThenBy(m => m.Name);

            ITypeSymbol searchType = GetTypeFromSpecifier(searchTypeSpec);

            List <MethodSpecifier> foundMethods = new List <MethodSpecifier>();

            // Find compatible methods

            foreach (IMethodSymbol availableMethod in availableMethods)
            {
                MethodSpecifier availableMethodSpec = ReflectionConverter.MethodSpecifierFromSymbol(availableMethod);

                // Check each argument whether it can be replaced by the wanted type
                for (int i = 0; i < availableMethodSpec.Arguments.Count; i++)
                {
                    ITypeSymbol argType = availableMethod.Parameters[i].Type;
                    BaseType    arg     = ReflectionConverter.BaseTypeSpecifierFromSymbol(argType);

                    if (arg == searchTypeSpec || searchType.IsSubclassOf(argType))
                    {
                        MethodSpecifier foundMethod = ReflectionConverter.MethodSpecifierFromSymbol(availableMethod);
                        foundMethod = TryMakeClosedMethod(foundMethod, arg, searchTypeSpec);

                        // Only add fully closed methods
                        if (foundMethod != null && !foundMethods.Contains(foundMethod))
                        {
                            foundMethods.Add(foundMethod);
                        }
                    }
                }
            }

            return(foundMethods);
        }