Herno
Herno

Reputation: 1597

How to parse a stored procedure signature in C# from plain text

I have a .sql file with stored procedures definitions.

I need to write a small program in C# that reads the file and obtains a list with the stored procedures signatures.

For example, this list should look like this:

[dbo].[procedureOne] ( int, int, varchar(250) out, nvarchar) 
[dbo].[procedureTwo] ( int, varchar(255) )
[dbo].[procedureThree] (  ) 
[dbo].[amazingSP] ( datetime, datetime ) 

Is there a way to do this using Regex?

What is the best approach?

Upvotes: 6

Views: 716

Answers (2)

Herno
Herno

Reputation: 1597

In the end, i implemented by hand a signature parser in C#. It took me some days to polish it, because there always were some cases which broke the parser causing unexpected results. It was fun coding it anyway. I'll upload the code when i have it finished if someone needs it.

Upvotes: 0

Paolo Tedesco
Paolo Tedesco

Reputation: 57242

Maybe you could do it with Regex, but I think writing a parser would be actually be easier in this case.

If you want, you can try out Irony, which is very simple to use.

Upvotes: 1

Related Questions