-
- MethodSpec result = null;
- MethodSpec tmp_move_next = null;
- PropertyExpr tmp_get_cur = null;
- TypeSpec tmp_enumerator_type = enumerator_type;
- foreach (MethodSpec mi in mg.Methods) {
- if (!mi.Parameters.IsEmpty)
- continue;
-
- // Check whether GetEnumerator is public
- if ((mi.Modifiers & Modifiers.AccessibilityMask) != Modifiers.PUBLIC)
- continue;
-
- enumerator_found = true;
-
- if (!GetEnumeratorFilter (ec, mi))
- continue;
-
- if (result != null) {
- if (TypeManager.IsGenericType (result.ReturnType)) {
- if (!TypeManager.IsGenericType (mi.ReturnType))
- continue;
-
- ec.Report.SymbolRelatedToPreviousError (t);
- ec.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.generic_ienumerable_type.GetSignatureForError ());
- return false;
- }
-
- // Always prefer generics enumerators
- if (!TypeManager.IsGenericType (mi.ReturnType)) {
- if (mi.DeclaringType.ImplementsInterface (result.DeclaringType) ||
- result.DeclaringType.ImplementsInterface (mi.DeclaringType))
- continue;
-
- ec.Report.SymbolRelatedToPreviousError (result);
- ec.Report.SymbolRelatedToPreviousError (mi);
- ec.Report.Warning (278, 2, loc, "`{0}' contains ambiguous implementation of `{1}' pattern. Method `{2}' is ambiguous with method `{3}'",
- TypeManager.CSharpName (t), "enumerable", result.GetSignatureForError (), mi.GetSignatureForError ());
- return false;
- }
- }
- result = mi;
- tmp_move_next = move_next;
- tmp_get_cur = get_current;
- tmp_enumerator_type = enumerator_type;
- if (mi.DeclaringType == t)
- break;