As I undersood from Preserving Hand-Coded Modifications to Generated Code
you have to specify position of preserve region(s) first in template.
And only regions in positions, defined by template, will be preserved.
It means that if different generated files need manual insertions in different places, the template will need to have a lot of preserve-region placeholders in all possible places where manual modification could be required.
It will be good to add an abilty to specify preserve regions in arbitrary places in generated files, rather than in templates, and still preserve code after generation.
Unfortunately, I am not sure that it is possible at all. May be generator should check context around the preserve block and compare with the context in a new generated file. If the match is found, it will insert preserve region in a new file to the matched position. If match is not found, show warning and move the preserve region to the end of the file.
Searching for matched context should use algorithms similar to WinDiff.
Hopefully someone else can suggest better ideas how to implement this
