I have just downloaded the trial of Resharper 7.1. My goal is to enforce a rule where our custom logger must be used on all catch blocks within our c# code-base. Example;
try{
// Any amount of code
}
catch(Exception e){
}
should be illegal, however:
try{
// Any amount of code
}
catch(Exception e){
Logger.LogException(e.Message, e);
}
is perfectly acceptable. To this end, I have the following pattern set up to detect and re-factor.
Search pattern:
try{
$anystatements$
}
catch($exceptiontype$ $exceptionarg$){
$anycatchstatements$
}
Replace pattern:
try{
$anystatements$
}
catch($exceptiontype$ $exceptionarg$){
Logger.LogException($exceptionarg$.Message, $exceptionarg$)
$anycatchstatements$
}
Resharper is detecting the smells fine, but is treating the replace pattern as a smell in itself as the added line for Logging is being matched by $anycatchstatement$
placeholder.
How can I define a placeholder to describe "match any number of statements in the catch block which are NOT calls to custom logger, and simply append a call to the logger"?
Unfortunatley no, i'm using Resharper 8 EAP (http://confluence.jetbrains.com/display/ReSharper/ReSharper+8+EAP) and it still don't has such option.
Provably you should take a look on Code Contracts, or http://www.postsharp.net/ or something similar.
Also Vladimir Reshetnikov was right - their team can help you a lot. You can easy contact with them trough email or web form. They have really good devs, and company allows direct communications with their customers. They are from Russia :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With