You can use a templated string-returning function and mix it in:
string codeGenerator(compileTimeArguments, Other...)(Other others)
{
string result = ...
(...) // build your code here
return result;
}
(...)
class C
{
mixin(codeGenerator!(args)(1, 2, 3));
}