In our solution we have a project that contains all the exceptions.
All of the exceptions inherit our base exception which inherits from ApplicationException.
开发者_如何学编程Our base exception includes a field for exception number.
What I would like to do is to run a script that creates a list with exception name, number and xml documentation.
Any idea how to do this?
If you want to generate a list of the custom exceptions in your application, you can use XML comments for this task. See the accepted answer to this question. As far as I know, the comments will not be able to access the error number property, but you can add an XML comment to that property and state the error number there.
A "script" is not going to be able to do this. You need a static code analyzer that traces all the method calls and detects when an object that derives from Exception is created and thrown. It gets sticky when the code calls methods in the .NET framework, you don't have the source code for it. System.Reflection is no help, it cannot reflect code.
This ultimately goes back to why exception specifications are such a bad idea.
Redgate had a product named "Exception Hunter" to do this. But they gave up on it, couldn't make it reliable enough. The discontinuation announcement is here. Don't buy too much stock on them blaming .NET 4 for this.
精彩评论