我正在使用StringBuilder.Append()
VB.NET 中的方法创建一个大型 SQL 语句。我想将整个 SQL 语句放在一个Append()
块中,并使用某种功能自动创建许多Append()
块来清理代码。
Append()
我正在使用 Visual Studio 2008 和 ReSharper 7,但除了手动添加块外,我找不到任何方法。ReSharper 的代码清理出人意料地没有帮助。
这可能吗?
编辑进一步澄清:
我希望能够编写一个长的 Append() 并让 IDE 或某些插件将其分成几个 Appends() 以达到审美目的。
例如:
Dim sql As New StringBuilder
sql.Append("SELECT Condition1 AS ""THIS_NAME"", Condition2 AS ""THIS_OTHER_NAME"", Condition3 AS ""ANOTHER_NAME"", Condition4 AS ""ANOTHER_NAME"", Condition5 AS ""THIS_NAME"" FROM MY_TABLE WHERE Condition1 = 'ThisValue' AND Condition2 = 'ThisOtherValue' AND Condition3 = 'ThisOtherValue' AND Condition4 = 'AnotherValue' AND Condition5 = 'SomeOtherValue'")
上面的 Append() 很长,可读性不是很好。但是,将 SQL 语句拆分为多个 Append 块时,有时很难使所有语法都正确。我想要一些插件将其转换为以下内容:
sql.Append("SELECT Condition1 AS ""THIS_NAME"",")
sql.Append(" Condition2 AS ""THIS_OTHER_NAME"",")
sql.Append(" Condition3 AS ""ANOTHER_NAME"",")
sql.Append(" Condition4 AS ""ANOTHER_NAME"",")
sql.Append(" Condition5 AS ""THIS_NAME"",")
sql.Append(" FROM MY_TABLE"",")
sql.Append(" WHERE Condition1 = 'ThisValue'")
....等等.. 它不必以这种方式精确格式化,只需将其分成几个 Append 语句的分隔符。