Вы могли также определить:
Ай... на самом деле это не хорошая идея, согласно Руководство .
А , возможный путь состоял бы в том, чтобы изменить файл в сценарии постфиксации, и затем фиксировать тот файл как независимое изменение, прежде, чем восстановить его в другом сценарии постфиксации...
Test1
is called, but unless you iterate through the result, you won't hit a breakpoint on yield break
.
Basically Test1
is transformed into a state machine which implements IEnumerable
for you... but all of the body of your method is inside that state machine, and unless you use the state machine by calling GetEnumerator()
and then MoveNext()
(or using a foreach
loop) you won't see your body execute.
See my general iterator article and my iterator implementation article for more information, and also two of Eric Lippert's blog posts: Psychic Debugging part one and Psychic Debugging part two.
Поскольку вы упомянули Python, я собираюсь указать, что генераторы в Python работают аналогично генераторам в C #. Есть небольшая разница в том, что только yield break
может преобразовать метод C # в генератор, в то время как Python-эквивалент вызывает StopIteration
- нет.
>>> def f():
... print "Beginning of generator"
... if False: yield
... print "End of generator"
...
>>> it = f()
>>> it
<generator object at 0x94fae2c>
>>> it.next()
Beginning of generator
End of generator
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration