/// /// Looks for extension method in this namespace /// public ArrayList LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name) { ArrayList found = null; if (declspaces != null) { IEnumerator e = declspaces.Values.GetEnumerator (); e.Reset (); while (e.MoveNext ()) { Class c = e.Current as Class; if (c == null) continue; if ((c.ModFlags & Modifiers.METHOD_EXTENSION) == 0) continue; ArrayList res = c.MemberCache.FindExtensionMethods (extensionType, name, c != currentClass); if (res == null) continue; if (found == null) found = res; else found.AddRange (res); } } if (external_exmethod_classes == null) return found; foreach (Type t in external_exmethod_classes) { MemberCache m = TypeHandle.GetMemberCache (t); ArrayList res = m.FindExtensionMethods (extensionType, name, true); if (res == null) continue; if (found == null) found = res; else found.AddRange (res); } return found; }
private static void FindEmbedFields(ModuleContainer module, ClassOrStruct cl, List<EmbedData> embeds) { foreach (var m in cl.Members) { var f = m as Field; if (f == null || f.OptAttributes == null || f.OptAttributes.Attrs.Count == 0) continue; if (!(f.TypeExpression is TypeExpression) || f.TypeExpression.Type != module.Compiler.BuiltinTypes.Type) continue; Mono.CSharp.Attribute embedAttr = null; foreach (var attr in f.OptAttributes.Attrs) { if (attr.Name == "Embed") { embedAttr = attr; break; } } if (embedAttr == null) continue; var e = new EmbedData(); e._index = _embedCount; _embedCount++; e._className = "__EmbedLoader" + e._index; e._field = f; e.source = e.mimeType = e.embedAsCFF = e.fontFamily = e.symbol = "null"; foreach (NamedArgument arg in embedAttr.NamedArguments) { if (!(arg.Expr is StringLiteral)) continue; var s = ((StringLiteral)(arg.Expr)).GetValueAsLiteral(); switch (arg.Name) { case "source": e.source = s; break; case "mimeType": e.mimeType = s; break; case "embedAsCFF": e.embedAsCFF = s; break; case "fontFamily": e.fontFamily = s; break; case "symbol": e.symbol = s; break; } } embeds.Add (e); } }
/// /// Looks for extension method in this namespace /// public List<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, ClassOrStruct currentClass, string name, int arity) { if (types == null) return null; List<MethodSpec> found = null; var invocation_type = currentClass == null ? InternalType.FakeInternalType : currentClass.CurrentType; // 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 (invocation_type, extensionType, name, arity); if (res == null) continue; if (found == null) { found = res; } else { found.AddRange (res); } } } return found; }
/// /// Looks for extension method in this namespace /// public ArrayList LookupExtensionMethod(Type extensionType, ClassOrStruct currentClass, string name) { ArrayList found = null; if (declspaces != null) { IEnumerator e = declspaces.Values.GetEnumerator(); e.Reset(); while (e.MoveNext()) { Class c = e.Current as Class; if (c == null) { continue; } if (!c.IsStaticClass) { continue; } ArrayList res = c.MemberCache.FindExtensionMethods(extensionType, name, c != currentClass); if (res == null) { continue; } if (found == null) { found = res; } else { found.AddRange(res); } } } if (external_exmethod_classes == null) { return(found); } foreach (Type t in external_exmethod_classes) { MemberCache m = TypeHandle.GetMemberCache(t); ArrayList res = m.FindExtensionMethods(extensionType, name, true); if (res == null) { continue; } if (found == null) { found = res; } else { found.AddRange(res); } } return(found); }
/// /// 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)); }
/// /// 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); }