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
- Ctrl+Shift+H (Replace in files)
- Select 'Use regular expressions'
- Enter this regex in the 'Find what' field: new SqlParameter({.*})
- Enter this in the 'Replace with' field: \1
- 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.
精彩评论