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.

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

3 Comments

"Smart way" is a poor choice of words, but the idea will work.
That is an option, but it would require me to extend/change the thrift compiler. I'm hoping to find a post generation solution.
@MatějZábský: There are no real templates. The generated code is assembled piece by piece during compiler run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.