Pattern catalog only valid for expression contexts?

    Hi there,

I'm trying to use the pattern catalog to replace all Log4Net usage, and I am a bit dismayed to discover that the Pattern catalog can only match expressions.
Is it by design?

I'd like to change all
private static readonly ILog $id$ = LogManager.GetLogger($arg$)
private static readonly IMyLog $id$ = LogProvider.GetLogger($arg$)

so I guess I'm back to regex :(


Comment actions Permalink

Yes, it's by design.

We will provide more power for Search with Pattern in the next version.

Please let us know about your specific scenarios in which you want to you this feature, this will help us implement all cases.

Comment actions Permalink

Hi Victor,

I would like to be able this to do type substitution on members (static or instance) as well as initializer substitutions.

For example, one of my projects has to migrate from log4net to a custom logger facade, I planned on using the pattern search/replace to change the following:

$L4nLog$ $Id$= $L4nLogManager$.GetLogger($arg$)


IMyFacadeLog $Id$ = MyFacadeManager.Get($arg$)

where :

$L4nLog$ : type : log4net.ILog
$id$ : member identifier
$L4nLogManager$ : type : log4net.LogManager
$args$ : arguments

So an example would be:
class MyClass

  private static ILog Log=LogManager.GetLogger(typeof(MyClass);
  private static ILog ImportantLog=LogManager.GetLogger("ImportantLog");

turned into

class MyClass{
  private static IMyFacadeLogLog Log=MyFacadeManager.Get(typeof(MyClass);
  private static IMyFacadeLogLog ImportantLog=MyFacadeManager.Get("ImportantLog");

I realize I can do this with regexps, but I lose the warm and fuzzy feeling I get whenever I use a clever resharper feature ;)


Edit: Added samples


Please sign in to leave a comment.