Skip to content

Commit 0372a13

Browse files
RexJaeschkeBillWagner
authored andcommitted
add support for extension GetEnumerator
1 parent 2f53536 commit 0372a13

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

standard/statements.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,15 @@ Before the process described in [§13.9.5.1](statements.md#13951-general), the f
11581158
If the process in [§13.9.5.1](statements.md#13951-general) completes without producing a single collection type, enumerator type, and iteration type, the following steps are taken:
11591159

11601160
- If there is an implicit conversion from `X` to the `System.Collections.IEnumerable` interface, then the collection type is this interface, the enumerator type is the interface `System.Collections.IEnumerator`, and the iteration type is `object`.
1161+
- Otherwise, determine whether the type 'X' has an appropriate `GetEnumerator` extension method:
1162+
- Perform extension method lookup on the type `X` with identifier `GetEnumerator`. If the member lookup does not produce a match, or it produces an ambiguity, or produces a match which is not a method group, an error is produced, and no further steps are taken. It is recommended that a warning be issued if member lookup produces anything except a method group or no match.
1163+
- Perform overload resolution using the resulting method group and a single argument of type `X`. If overload resolution produces no applicable methods, results in an ambiguity, or results in a single best method but that method is not accessible, an error is produced an no further steps are taken.
1164+
- This resolution permits the first argument to be passed by ref if `X` is a struct type, and the ref kind is `in`.
1165+
- If the return type `E` of the `GetEnumerator` method is not a class, struct or interface type, an error is produced, and no further steps are taken.
1166+
- Member lookup is performed on `E` with the identifier `Current` and no type arguments. If the member lookup produces no match, the result is an error, or the result is anything except a public instance property that permits reading, an error is produced, and no further steps are taken.
1167+
- Member lookup is performed on `E` with the identifier `MoveNext` and no type arguments. If the member lookup produces no match, the result is an error, or the result is anything except a method group, an error is produced, and no further steps are taken.
1168+
- Overload resolution is performed on the method group with an empty argument list. If overload resolution results in no applicable methods, results in an ambiguity, or results in a single best method but that method is either static or not public, or its return type is not `bool`, an error is produced, and no further steps are taken.
1169+
- The collection type is `X`, the enumerator type is `E`, and the iteration type is the type of the `Current` property.
11611170
- Otherwise, an error is produced, and no further steps are taken.
11621171

11631172
A `foreach` statement of the form

0 commit comments

Comments
 (0)