modelsbuilder/ModelsBuilder.Original

v4: Generator should be swappable / extendable

Opened this issue · 0 comments

bielu commented

HI @zpqrtbnk ,
On time when I was working with my extension for MB v4, I hit that issue I need split generation separation in to 2 separate files and in time of work on that I noticed to do that I need modify Our.ModelsBuilder.Building.Generator and I noticed we actually dont have way to hijack here as we dont register that in container and we dont have any event which would allow me to change that part:

  var codeModel = CreateModels(modelsNamespace, files, (name, code) =>
            {
                var filename = Path.Combine(modelsDirectory, name + ".generated.cs");
                File.WriteAllText(filename, code);
            });

Which I would extend with additional option after as example:

  var codeTransformation = CreateTransformation(modelsNamespace, files, (name, code) =>
            {
                var filename = Path.Combine(modelsDirectory, name + ".transformation.generated.cs");
                File.WriteAllText(filename, code);
            });

and later

if (bin != null)
            {
                // build
                foreach (var file in Directory.GetFiles(modelsDirectory, "*.generated.cs"))
                    files[file] = File.ReadAllText(file);
                var compiler = new Compiler(_options.LanguageVersion);
                // FIXME what is the name of the DLL as soon as we accept several namespaces = an option?
                compiler.Compile(codeModel.AssemblyName, files, bin);
                compiler.Compile(codeTransformation.AssemblyName, files, bin);
            }