/// <summary>
        /// Adds extension methods to <paramref name="res"/>.
        /// </summary>
        public static void AddExtensions(LanguageProperties language, ArrayList res, IClass callingClass, IReturnType resolvedType)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (res == null)
            {
                throw new ArgumentNullException("res");
            }
            if (resolvedType == null)
            {
                throw new ArgumentNullException("resolvedType");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }

            // convert resolvedType into direct type to speed up the IsApplicable lookups
            resolvedType = resolvedType.GetDirectReturnType();

            foreach (IMethodOrProperty mp in CtrlSpaceResolveHelper.FindAllExtensions(language, callingClass))
            {
                TryAddExtension(language, res, mp, resolvedType);
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds extension methods to <paramref name="res"/>.
        /// </summary>
        public static void AddExtensions(LanguageProperties language, Action <IMethodOrProperty> methodFound, IClass callingClass, IReturnType resolvedType, bool searchInAllNamespaces = false)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (methodFound == null)
            {
                throw new ArgumentNullException("methodFound");
            }
            if (resolvedType == null)
            {
                throw new ArgumentNullException("resolvedType");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }

            // convert resolvedType into direct type to speed up the IsApplicable lookups
            resolvedType = resolvedType.GetDirectReturnType();

            foreach (IMethodOrProperty mp in CtrlSpaceResolveHelper.FindAllExtensions(language, callingClass, searchInAllNamespaces))
            {
                TryAddExtension(language, methodFound, mp, resolvedType);
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds extension methods to <paramref name="res"/>.
        /// </summary>
        public static void AddExtensions(LanguageProperties language, ArrayList res, IClass callingClass, IReturnType resolvedType)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (res == null)
            {
                throw new ArgumentNullException("res");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }
            if (resolvedType == null)
            {
                throw new ArgumentNullException("resolvedType");
            }

            bool supportsExtensionMethods    = language.SupportsExtensionMethods;
            bool supportsExtensionProperties = language.SupportsExtensionProperties;

            if (supportsExtensionMethods || supportsExtensionProperties)
            {
                ArrayList list        = new ArrayList();
                IMethod   dummyMethod = new DefaultMethod("dummy", VoidReturnType.Instance, ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass);
                CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod);
                CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass);

                bool searchExtensionsInClasses = language.SearchExtensionsInClasses;
                foreach (object o in list)
                {
                    if (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty)
                    {
                        TryAddExtension(language, res, o as IMethodOrProperty, resolvedType);
                    }
                    else if (searchExtensionsInClasses && o is IClass)
                    {
                        IClass c = o as IClass;
                        if (c.HasExtensionMethods)
                        {
                            if (supportsExtensionProperties)
                            {
                                foreach (IProperty p in c.Properties)
                                {
                                    TryAddExtension(language, res, p, resolvedType);
                                }
                            }
                            if (supportsExtensionMethods)
                            {
                                foreach (IMethod m in c.Methods)
                                {
                                    TryAddExtension(language, res, m, resolvedType);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
        public static IList <IMethodOrProperty> FindAllExtensions(LanguageProperties language, IClass callingClass)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }

            HashSet <IMethodOrProperty> res = new HashSet <IMethodOrProperty>();

            bool supportsExtensionMethods    = language.SupportsExtensionMethods;
            bool supportsExtensionProperties = language.SupportsExtensionProperties;

            if (supportsExtensionMethods || supportsExtensionProperties)
            {
                ArrayList list        = new ArrayList();
                IMethod   dummyMethod = new DefaultMethod("dummy", callingClass.ProjectContent.SystemTypes.Void,
                                                          ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass);
                CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod);
                CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass);

                bool searchExtensionsInClasses = language.SearchExtensionsInClasses;
                foreach (object o in list)
                {
                    IMethodOrProperty mp = o as IMethodOrProperty;
                    if (mp != null && mp.IsExtensionMethod &&
                        (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty))
                    {
                        res.Add(mp);
                    }
                    else if (searchExtensionsInClasses && o is IClass)
                    {
                        IClass c = o as IClass;
                        if (c.HasExtensionMethods)
                        {
                            if (supportsExtensionProperties)
                            {
                                foreach (IProperty p in c.Properties)
                                {
                                    if (p.IsExtensionMethod)
                                    {
                                        res.Add(p);
                                    }
                                }
                            }
                            if (supportsExtensionMethods)
                            {
                                foreach (IMethod m in c.Methods)
                                {
                                    if (m.IsExtensionMethod)
                                    {
                                        res.Add(m);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(res.ToList());
        }