This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Description
Problem statement: using syntax inside a yield return IEnumerable results in confusing and inconsistent traces
Action: Clarify the usage via documentation or utility methods that make such authoring more convenient
Expectation:
When tracing inside an IEnumerable's production code and the consumer/processor code...
My Trace should look like
DoStuff
DoStuff > EnumerateItemFirstPart
DoStuff > ProcessItem
DoStuff > EnumerateItemSecondPart
DoStuff > ProcessItem
Reality:
My Trace would look like
DoStuff
DoStuff > EnumerateItemFirstPart
DoStuff > EnumerateItemFirstPart > ProcessItem
DoStuff > EnumerateItemSecondPart
DoStuff > EnumerateItemSecondPart > ProcessItem
Demonstrate the problem:
class DemonstrateTheProblem
{
public static IEnumerable<int> ShowIt()
{
using (StartFirstPartTrace())
{
for (int i = 0; i < 10; i++)
{
// StartFirstPartTrace will be leaked out of right here - e.g. the code consuming the IEnumerable will say that it is inside StartFirstPartTrace()
yield return i;
}
}
// Including a SecondPart to negate the obvious solution of wrapping the IEnumerator
using (StartSecondPartTrace())
{
for (int i = 0; i < 10; i++)
{
// StartSecondPartTrace will be leaked out of right here - e.g. the code consuming (a foreach for instance) will now
yield return i;
}
}
}
}