The marshalling generator types in Microsoft.Interop.SourceGeneration pass a StubCodeContext to a method that builds an IMarshallingGenerator, which takes a TypePositionInfo and StubCodeContext each time it generates a method, and has different behavior depending on those.
If instead, a constructor method composed an object based on the StubCodeContext and TypePositionInfo, and the methods on the object took no parameters, the generator could be much easier to debug and unit test, as the composition of the object would be the only thing that impacts the generated code. This would also make it easy to unit test, since tests could compose an object and test the behavior of the generator without need to create a TypePositionInfo and StubCodeContext.