Mono.CSharp.Namespace.LookupExtensionMethod C# (CSharp) Method

LookupExtensionMethod() public method

public LookupExtensionMethod ( System.TypeSpec extensionType, TypeContainer invocationContext, string name, int arity ) : List
extensionType System.TypeSpec
invocationContext TypeContainer
name string
arity int
return List
		public List<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, TypeContainer invocationContext, string name, int arity)
		{
			if (types == null)
				return null;

			List<MethodSpec> found = null;

			// TODO: Add per namespace flag when at least 1 type has extension

			foreach (var tgroup in types.Values) {
				foreach (var ts in tgroup) {
					if ((ts.Modifiers & Modifiers.METHOD_EXTENSION) == 0)
						continue;

					var res = ts.MemberCache.FindExtensionMethods (invocationContext, extensionType, name, arity);
					if (res == null)
						continue;

					if (found == null) {
						found = res;
					} else {
						found.AddRange (res);
					}
				}
			}

			return found;
		}

Usage Example

Example #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 NamespaceContainer scope)
        {
            List <MethodSpec> candidates = null;

            foreach (Namespace n in GetUsingTable())
            {
                var a = n.LookupExtensionMethod(this, extensionType, 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(this, extensionType, 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));
        }
All Usage Examples Of Mono.CSharp.Namespace::LookupExtensionMethod