LookupExtensionMethod() public méthode

public LookupExtensionMethod ( System.TypeSpec extensionType, string name, int arity, NamespaceEntry &scope ) : IList
extensionType System.TypeSpec
name string
arity int
scope NamespaceEntry
Résultat IList
Exemple #1
0
        ///
        /// Does extension methods look up to find a method which matches name and extensionType.
        /// Search starts from this namespace and continues hierarchically up to top level.
        ///
        public IList <MethodSpec> LookupExtensionMethod(TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
        {
            List <MethodSpec> candidates = null;

            foreach (Namespace n in GetUsingTable())
            {
                var a = n.LookupExtensionMethod(extensionType, RootContext.ToplevelTypes, name, arity);
                if (a == null)
                {
                    continue;
                }

                if (candidates == null)
                {
                    candidates = a;
                }
                else
                {
                    candidates.AddRange(a);
                }
            }

            scope = parent;
            if (candidates != null)
            {
                return(candidates);
            }

            if (parent == null)
            {
                return(null);
            }

            //
            // Inspect parent namespaces in namespace expression
            //
            Namespace parent_ns = ns.Parent;

            do
            {
                candidates = parent_ns.LookupExtensionMethod(extensionType, RootContext.ToplevelTypes, name, arity);
                if (candidates != null)
                {
                    return(candidates);
                }

                parent_ns = parent_ns.Parent;
            } while (parent_ns != null);

            //
            // Continue in parent scope
            //
            return(parent.LookupExtensionMethod(extensionType, name, arity, ref scope));
        }
Exemple #2
0
        MethodGroupExpr ResolveOverloadExtensions(ResolveContext ec, ref Arguments arguments, NamespaceEntry ns, Location loc)
        {
            // Use normal resolve rules
            MethodGroupExpr mg = base.OverloadResolve (ec, ref arguments, ns != null, loc);
            if (mg != null)
                return mg;

            if (ns == null)
                return null;

            // Search continues
            int arity = type_arguments == null ? -1 : type_arguments.Count;
            ExtensionMethodGroupExpr e = ns.LookupExtensionMethod (type, Name, arity, loc);
            if (e == null)
                return base.OverloadResolve (ec, ref arguments, false, loc);

            e.ExtensionExpression = ExtensionExpression;
            e.SetTypeArguments (ec, type_arguments);
            return e.ResolveOverloadExtensions (ec, ref arguments, e.namespace_entry, loc);
        }
        ///
        /// Does extension methods look up to find a method which matches name and extensionType.
        /// Search starts from this namespace and continues hierarchically up to top level.
        ///
        public ExtensionMethodGroupExpr LookupExtensionMethod(Type extensionType, ClassOrStruct currentClass, string name, Location loc)
        {
            ArrayList candidates = null;

            if (currentClass != null)
            {
                candidates = ns.LookupExtensionMethod(extensionType, currentClass, name);
                if (candidates != null)
                {
                    return(new ExtensionMethodGroupExpr(candidates, this, extensionType, loc));
                }
            }

            foreach (Namespace n in GetUsingTable())
            {
                ArrayList a = n.LookupExtensionMethod(extensionType, null, name);
                if (a == null)
                {
                    continue;
                }

                if (candidates == null)
                {
                    candidates = a;
                }
                else
                {
                    candidates.AddRange(a);
                }
            }

            if (candidates != null)
            {
                return(new ExtensionMethodGroupExpr(candidates, parent, extensionType, loc));
            }

            if (parent == null)
            {
                return(null);
            }

            //
            // Inspect parent namespaces in namespace expression
            //
            Namespace parent_ns = ns.Parent;

            do
            {
                candidates = parent_ns.LookupExtensionMethod(extensionType, null, name);
                if (candidates != null)
                {
                    return(new ExtensionMethodGroupExpr(candidates, parent, extensionType, loc));
                }

                parent_ns = parent_ns.Parent;
            } while (parent_ns != null);

            //
            // Continue in parent scope
            //
            return(parent.LookupExtensionMethod(extensionType, currentClass, name, loc));
        }