Reflection.Emit
is for generating IL code, not for generating high-level language code. So if your target language is IronPython, building it up in a StringBuilder
is probably your best bet.
It of course depends on your needs. If all you want to do is just generate code without wanting to change the order of methods, or modify methods after they've been defined etc., just constructing code in a StringBuilder
and then compiling it would be the easiest way.