开发者

In C# VS2008 how to replace new SqlParameter("@values", SqlDbType.SomeType, 1500)) to ("@values", SqlDbType.SomeType, 1500

I have a lot of C# VS2008 code that looks like this:

new SqlParameter("@Description", SqlDbType.NChar, 1500)

or this:

new SqlParameter("@IsRequired", SqlDbType.Bit)

I want to change this code throughout my project 开发者_开发知识库— there are thousands of occurrences of this pattern.

How can I write a regular expression to remove the new SqlParameter() portion and just leave:

"@Description", SqlDbType.NChar, 1500

and

"@IsRequired", SqlDbType.Bit

?


If you are looking for a simple search/replace, then try

  1. Ctrl+Shift+H (Replace in files)
  2. Select 'Use regular expressions'
  3. Enter this regex in the 'Find what' field: new SqlParameter({.*})
  4. Enter this in the 'Replace with' field: \1
  5. Hit 'Replace All'


You can write a script that use regular expression to handle the parsing and replacing.


Read the question that I posted here.

More Efficient Way of Adding Parameters to a SqlCommand .NET

Regardless of how you do it, it will still create a SqlParameter object. It's all about personal preference. The question i posted has a few different ways of doing it.


Do a replace all on new SqlParameter( with blank.
Then, do a replace all on ) with blank.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜