1

I use a tool that generates c# source code (thrift), one file per type. I would like to amalgamate all of the types to a single compilable source file. I say compilable because simply concatenating the text from each file will produce a single file that does not compile do to the layout, e.g. multiple using blocks.

Is there a command line tool that will do this, or do I need to create one and if so what libs should I be looking at to do so.

======= EDIT ======

Didn't find anything and wimped out of contributing to thrift compiler source, so I knocked this up which does the trick: https://github.com/myles-mcdonnell/SourceMeld

Now I can add two pre-build steps in VS, one to exe thrift to generate source files, two to amalgamate to one file (the file that is include in project) and I have a seamless build process at dev time.

Myles McDonnell
  • 12,943
  • 17
  • 66
  • 116

1 Answers1

4

You can concatenate the source files if you write them in smart way.

See, this doesn't work:

using External.Name.Space;
namespace My.Name.Space
{
    ...
}

using External.Name.Space;
namespace My.Name.Space
{
    ...
}

But this does:

namespace My.Name.Space
{
    using External.Name.Space;

    ...
}

namespace My.Name.Space
{
    using External.Name.Space;

    ...
}

These two notations are mostly functionally equivalent (for details, see "Should Usings be inside or outside the namespace").

Tools like ReSharper can transform all your source files from the first notation to the second in several clicks (even the free trial version can do that).

EDIT:

I forgot you are using a code generator. Then you have these options:

  1. Change Thrift's templates (I'm not familiar with the tool, but I would expect it has templates of some sort).
  2. Write a tool which moves the usings from outside of a namespace within. This should be a single Regex.Replace call.
  3. Write a tool which reads the concatenated file and moves all the usings to the top. Again, this should be extremely simple.
Community
  • 1
  • 1
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114