2

I'm currently creating many files using t4 templates in vs2015.

My code comes out all misaligned (it's worst in other spot of the generated code)

example -

                       public bool Add()
                {
                    var returnValue = false;

                    using (var context = new ApmEntities())
                    {
                        context.Entry(this).State = EntityState.Added;
                                            foreach (var item in this.MissionCriticalities)
                        {
                            context.Entry(item).State = EntityState.Modified;
                        }

                        var number = context.SaveChanges();
                        returnValue = number > 0;
                    }

                return returnValue;
                }

Is there a way to automatically run formatting (similar to doing Ctrl - K - D) on the file?

I'm creating the file with

fileManager.StartNewFile(entity.Name + "DbExtra" + ".cs");

and at the end of the file doing a

fileManager.Process();

(Similar to the t4 that generates objects when using database first entity framework)

Thanks

Lareau
  • 1,982
  • 1
  • 26
  • 47

1 Answers1

0

You can format it with "\t" or "\n" or normale spaces directly in your file creation. It depends on how your "CreationFile" looks like and how this is formated. I don't think that you can format that in another way per code, because with your t4 script you will say how the file should look like.

But what you also can try is: Use the CodeCleanup From Resharper, if you have, and write a macro which will save every "Save" action of a file: How can I configure ReSharper's code cleanup on save?

I use that and its very great. Its formated the different files in that way which I want, sorted properties, usings and much more.

Try it :-)

Community
  • 1
  • 1
Destra
  • 1
  • 3