Note that there are some explanatory texts on larger screens.

plurals
  1. POC# to format (indent, align) C# properly
    text
    copied!<p>We have a code generator that <a href="http://www.codegeneration.net/tiki-index.php?page=CodeMungerModel" rel="nofollow noreferrer">munges</a> the schema of a given database to automate our inhouse n-tier architecture. The output is various C# partial classes, one per file. </p> <p>In the code to munge all the strings, we try and keep on top of the indenting and formatting as much as possible, but invariably when you come to open the file in Visual Studio the formatting is awry. A quick ctrl-k, ctrl-d fixes it, but obviously this reformatting is lost the next time the class is generated.</p> <p>What I'd like to know, is if there's a way I can somehow automatically format the contents of the textfile in the same way Visual Studio does? </p> <p>Pseudocode</p> <pre><code>Create "code" object, passing text file to constructor Invoke "format" method Re-save text file </code></pre> <p>Any help greatly appreciated.</p> <p><strong>EDIT:</strong> I should clarify - I want to be able to invoke the formatting from my C# code that creates the textfile containing my generated C#. The format of the code can be standardised (doesn't have to be per-developer), and I don't want to have to install any 3rd-party apps.</p> <p>I seem to remember there's a namespace containing loads of classes for creating C# in C#: <a href="http://msdn.microsoft.com/en-us/library/system.codedom(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.codedom(VS.80).aspx</a>, but I'm not sure if it contains any classes that could help.</p> <p><strong>FURTHER EDIT:</strong> My code generator is a winforms app deployed via a click-once install. It's used by many developers in-house. I need a solution that doesn't require each developer to have a tool installed on their machine.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload