-
- MethodInfo result = null;
- MethodInfo tmp_move_next = null;
- PropertyExpr tmp_get_cur = null;
- Type tmp_enumerator_type = enumerator_type;
- foreach (MethodInfo mi in mg.Methods) {
- if (TypeManager.GetParameterData (mi).Count != 0)
- continue;
-
- // Check whether GetEnumerator is public
- if ((mi.Attributes & MethodAttributes.Public) != MethodAttributes.Public)
- continue;
-
- if (IsOverride (mi))
- continue;
-
- enumerator_found = true;
-
- if (!GetEnumeratorFilter (ec, mi))
- continue;
-
- if (result != null) {
- if (TypeManager.IsGenericType (result.ReturnType)) {
- if (!TypeManager.IsGenericType (mi.ReturnType))
- continue;
-
- MethodBase mb = TypeManager.DropGenericMethodArguments (mi);
- Report.SymbolRelatedToPreviousError (t);
- Report.Error(1640, loc, "foreach statement cannot operate on variables of type `{0}' " +
- "because it contains multiple implementation of `{1}'. Try casting to a specific implementation",
- TypeManager.CSharpName (t), TypeManager.CSharpSignature (mb));
- return false;
- }
-
- // Always prefer generics enumerators
- if (!TypeManager.IsGenericType (mi.ReturnType)) {
- if (TypeManager.ImplementsInterface (mi.DeclaringType, result.DeclaringType) ||
- TypeManager.ImplementsInterface (result.DeclaringType, mi.DeclaringType))
- continue;
-
- Report.SymbolRelatedToPreviousError (result);
- Report.SymbolRelatedToPreviousError (mi);
- Report.Warning (278, 2, loc, "`{0}' contains ambiguous implementation of `{1}' pattern. Method `{2}' is ambiguous with method `{3}'",
- TypeManager.CSharpName (t), "enumerable", TypeManager.CSharpSignature (result), TypeManager.CSharpSignature (mi));
- return false;
- }
- }
- result = mi;
- tmp_move_next = move_next;
- tmp_get_cur = get_current;
- tmp_enumerator_type = enumerator_type;
- if (mi.DeclaringType == t)
- break;
- }
-
- if (result != null) {
- move_next = tmp_move_next;
- get_current = tmp_get_cur;
- enumerator_type = tmp_enumerator_type;
- MethodInfo[] mi = new MethodInfo[] { (MethodInfo) result };
- get_enumerator = new MethodGroupExpr (mi, enumerator_type, loc);
-
- if (t != expr.Type) {
- expr = Convert.ExplicitConversion (
- ec, expr, t, loc);
- if (expr == null)
- throw new InternalErrorException ();
- }
-
- get_enumerator.InstanceExpression = expr;
- get_enumerator.IsBase = t != expr.Type;
-
- return true;