C#格式化(缩进,对齐)C#正确 [英] C# to format (indent, align) C# properly

查看:726
本文介绍了C#格式化(缩进,对齐)C#正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个代码生成器, munges 给定的模式数据库自动化室内我们的n层体系结构。输出是各种各样的C#部分类,每个文件一个。

We have a code generator that munges the schema of a given database to automate our inhouse n-tier architecture. The output is various C# partial classes, one per file.

在代码munge所有的字符串,我们尽量保持在缩进和格式化尽可能的顶部,但总是当你来到打开该文件Visual Studio中的格式是歪。快速CTRL-K,CTRL-D的修复,但显然这格式化丢失生成类的下一次。

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.

我想知道什么是如果有一种方法,我可以以某种方式自动格式化文本文件的内容以同样的方式Visual Studio的呢?

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?

伪代码

Create "code" object, passing text file to constructor
Invoke "format" method
Re-save text file

任何帮助。不胜感激

编辑:
我要澄清 - 我希望能够从我的C#代码调用格式创建包含我生成的C#文本文件。代码的格式都可以标准化(并不一定是每个开发者),我不希望有安装任何第三方应用程序。

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.

我似乎记得有含类负载,在C#创建C#命名空间: HTTP ://msdn.microsoft.com/en-us/library/system.codedom (VS.80)的.aspx,但我不知道,如果它包含可以帮助任何类

I seem to remember there's a namespace containing loads of classes for creating C# in C#: http://msdn.microsoft.com/en-us/library/system.codedom(VS.80).aspx, but I'm not sure if it contains any classes that could help.

进一步编辑:
我的代码生成器是通过部署一个WinForms应用程序点击安装一次。它被许多开发商在房子里。我需要不需要每个开发者有他们的计算机上安装的工具的解决方案。

FURTHER 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.

推荐答案

要展开切里安的回答

NArrange 将允许你做了很多代码格式化。它是开源的,并且源可在其网站上,这样你可能会集成,并与您的工具redistbute它。

NArrange will allow you to do a lot of code formatting. It is open source, and the source is available on their site, so you could potentially integrate and redistbute it with your tool.

您应该只需要DLL的,只是看如何调用该格式的exe文件。它还将创建格式化代码的备份。这确实是一个很好的工具,如果它符合您的需求。

You should only need the dll's and just look at the exe on how to call the formatting. It will also create a backup of the code being formatted. It is really a nice tool if it fits your needs.

这篇关于C#格式化(缩进,对齐)C#正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆