1

After searching Google, and finding only answers to XML indent, "just use Visual Studio's auto indent" and "that would be crazy to write your own auto-indenter" I've decided to come to the good place: StackOverflow...

Question: 1. How do I add an 'indent' to a programmatically created file? - I would be generating the files via the System.IO class / streamwriter, unless someone can tell me of a better way, I just want to generate a file from my asp.net page, a windows app or possible a batch file (well, maybe not this last one)... to generate a class file, such as Employee.vb OR EmployeeDAL.vb

Why: I've decided that I'm a bit bored of writing the same BOL and DAL code for every database table I write, and at the moment I'm stuck with ASP.NET due to work constraints, otherwise I would just move over to something like Ruby on Rails or some PHP framework, but this isn't an option, so please don't suggest this.

So... I know how to get the names of all my table columns, their data types, their lengths,... yadda yaddda..., and I haven't actually fleshed out a working file, but from experience / knowledge, and a bit of googling I think the main bits will be 'fairly easy'.

However all I really want to know, is how to I add an indentation when I create my file?

Over thinking it: Perhaps, I'm over thinking it, and when I sit down to write it, I'll realise, I just need to add some spaces to my string...

"    private _" & db_field_name & " as " variable_type(db_type)
  • Any help appreciated...
  • Cheers.

Ps... We're using .NET 2.0 - I know, I know, there are so many reasons we should be using Ruby, PHP, or .NET 4.0 (hopefully this is coming this year - to our team) - but there is nothing I can do about it at the moment, and we use .NET.

4

2 に答える 2

2

これを行うためにT4 テンプレートを使用しない理由はありますか?

また、コード生成によって作成されたファイルをインデントするために利用できる魔法はありません。あなたはそれをする責任があります。もちろん、T4 を使用してコードを生成する場合は、ほとんどの場合、これについて心配する必要はありません (T4 の性質上、この質問はほとんどの場合意味がありません)。

于 2011-04-04T14:10:46.450 に答える
2

IndentedTextWriter クラスは、便利なインデントをサポートしているようです。

System.CodeDom 名前空間は、実行しようとしていることに適用できる可能性があるため、一般的に確認することをお勧めします。

于 2011-04-04T18:15:50.017 に答える